Changeset 8504
- Timestamp:
- 12/28/07 18:01:22 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (2 diffs)
- trunk/activerecord/test/associations_test.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8456 r8504 1 1 *SVN* 2 3 * Don't unnecessarily load has_many associations in after_update callbacks. Closes #6822 [stopdropandrew, canadaduane] 2 4 3 5 * Eager belongs_to :include infers the foreign key from the association name rather than the class name. #10517 [Jonathan Viney] trunk/activerecord/lib/active_record/associations.rb
r8481 r8504 1080 1080 if new_record? 1081 1081 association 1082 elsif association.loaded? 1083 association.select { |record| record.new_record? } 1082 1084 else 1083 association. select { |record| record.new_record? }1085 association.target.select { |record| record.new_record? } 1084 1086 end.each do |record| 1085 1087 errors.add "#{association_name}" unless record.valid? … … 1098 1100 elsif association.respond_to?(:loaded?) && association.loaded? 1099 1101 association.select { |record| record.new_record? } 1102 elsif association.respond_to?(:loaded?) && !association.loaded? 1103 association.target.select { |record| record.new_record? } 1100 1104 else 1101 1105 [] trunk/activerecord/test/associations_test.rb
r8486 r8504 73 73 end 74 74 end 75 75 76 76 class AssociationProxyTest < Test::Unit::TestCase 77 77 fixtures :authors, :posts, :categorizations, :categories, :developers, :projects, :developers_projects 78 78 79 79 def test_proxy_accessors 80 80 welcome = posts(:welcome) … … 83 83 welcome.author.class # force load target 84 84 assert_equal welcome.author, welcome.author.proxy_target 85 85 86 86 david = authors(:david) 87 87 assert_equal david, david.posts.proxy_owner … … 89 89 david.posts.first # force load target 90 90 assert_equal david.posts, david.posts.proxy_target 91 91 92 92 assert_equal david, david.posts_with_extension.testing_proxy_owner 93 93 assert_equal david.class.reflect_on_association(:posts_with_extension), david.posts_with_extension.testing_proxy_reflection … … 99 99 david = authors(:david) 100 100 101 david.posts << (post = Post.new(:title => "New on Edge", :body => "More cool stuff!")) 102 assert !david.posts.loaded? 103 assert david.posts.include?(post) 104 end 105 106 def test_push_has_many_through_does_not_load_target 107 david = authors(:david) 108 101 109 david.categories << categories(:technology) 102 110 assert !david.categories.loaded? 103 111 assert david.categories.include?(categories(:technology)) 112 end 113 114 def test_push_followed_by_save_does_not_load_target 115 david = authors(:david) 116 117 david.posts << (post = Post.new(:title => "New on Edge", :body => "More cool stuff!")) 118 assert !david.posts.loaded? 119 david.save 120 assert !david.posts.loaded? 121 assert david.posts.include?(post) 104 122 end 105 123 … … 773 791 assert_equal 3, companies(:first_firm).clients_of_firm(true).size 774 792 end 775 793 794 def test_build_followed_by_save_does_not_load_target 795 new_client = companies(:first_firm).clients_of_firm.build("name" => "Another Client") 796 assert companies(:first_firm).save 797 assert !companies(:first_firm).clients_of_firm.loaded? 798 end 799 776 800 def test_build_without_loading_association 777 801 first_topic = topics(:first) … … 824 848 companies(:first_firm).clients_of_firm.create([{"name" => "Another Client"}, {"name" => "Another Client II"}]) 825 849 assert_equal 3, companies(:first_firm).clients_of_firm(true).size 850 end 851 852 def test_create_followed_by_save_does_not_load_target 853 new_client = companies(:first_firm).clients_of_firm.create("name" => "Another Client") 854 assert companies(:first_firm).save 855 assert !companies(:first_firm).clients_of_firm.loaded? 826 856 end 827 857