Ticket #8713: 0001-Fix-regression-in-r7076-to-save-built-records-on-an.patch
| File 0001-Fix-regression-in-r7076-to-save-built-records-on-an.patch, 3.0 kB (added by shoe, 8 months ago) |
|---|
-
a/activerecord/lib/active_record/associations.rb
old new 986 986 if association.respond_to?(:loaded?) 987 987 if new_record? 988 988 association 989 els e989 elsif association.loaded? 990 990 association.select { |record| record.new_record? } 991 else 992 association.target.select { |record| record.new_record? } 991 993 end.each do |record| 992 994 errors.add "#{association_name}" unless record.valid? 993 995 end … … 1004 1006 association 1005 1007 elsif association.respond_to?(:loaded?) && association.loaded? 1006 1008 association.select { |record| record.new_record? } 1009 elsif association.respond_to?(:loaded?) && !association.loaded? 1010 association.target.select { |record| record.new_record? } 1007 1011 else 1008 1012 [] 1009 1013 end 1010 1014 1011 1015 records_to_save.each { |record| association.send(:insert_record, record) } unless records_to_save.blank? 1012 1016 1013 1017 # reconstruct the SQL queries now that we know the owner's id 1014 1018 association.send(:construct_sql) if association.respond_to?(:construct_sql) 1015 1019 end_eval -
a/activerecord/test/associations_test.rb
old new 687 687 assert_equal 3, companies(:first_firm).clients_of_firm(true).size 688 688 end 689 689 690 def test_save_without_validations_after_build_without_loading_association 691 first_topic = topics(:first) 692 Reply.column_names 693 694 assert_equal 1, first_topic.replies.size 695 new_reply = nil 696 697 assert_no_queries do 698 new_reply = first_topic.replies.build(:title => "Not saved", :content => "Superstars") 699 assert new_reply.new_record? 700 assert_equal 2, first_topic.replies.size 701 end 702 assert first_topic.save(false) 703 assert !new_reply.new_record? 704 assert !first_topic.replies.loaded? 705 706 assert_equal 2, first_topic.replies.to_ary.size 707 end 708 690 709 def test_build_without_loading_association 691 710 first_topic = topics(:first) 692 711 Reply.column_names