has_many behaviour on new records

It is a bug and we fixed it yesterday on master. I’m backporting the fixes to 3-2-stable right now.

Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca

Thanks for your fast reply. I just checked out the 3-2-stable branch and the count problem is fixed. However the sum issue

ruby-1.9.3-head :003 > Invoice.new.bikes.sum(&:price)   Bike Load (30.4ms) SELECT "bikes".* FROM "bikes" WHERE "bikes"."invoice_id" IS NULL => 809577.5

still remains. But the same fix works for the sum method

activerecord/lib/active_record/associations/collection_association.rb

      # Calculate sum using SQL, not Enumerable       def sum(*args)         return 0 if owner.new_record?         if block_given?           scoped.sum(*args) { |*block_args| yield(*block_args) }         else           scoped.sum(*args)         end       end

I do apologize for not making a pull request, but I don't know how to do that propperly with test etc, and right now, I've got no nerve to read a howto on that topic.

Yes, are are acknowledged of these issues but we didn’t figure out the best way to solve they.

See https://github.com/rails/rails/issues/5215

Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca