Ticket #11514: inspect_on_new_object_association_does_not_reload_association_2.diff
| File inspect_on_new_object_association_does_not_reload_association_2.diff, 1.9 kB (added by acirugeda, 6 months ago) |
|---|
-
activerecord/test/cases/associations_test.rb
old new 141 141 assert_equal 1, josh.posts.size 142 142 end 143 143 144 def test_inspect_does_not_lose_additions_to_new_record 145 andres = Author.new(:name => "Andres") 146 andres.posts.build(:title => "New on Edge", :body => "More cool stuff!") 147 assert !andres.posts.loaded? 148 assert_equal 1, andres.posts.size 149 andres.posts.inspect 150 assert !andres.posts.loaded? 151 assert_equal 1, andres.posts.size 152 end 153 144 154 def test_save_on_parent_does_not_load_target 145 155 david = developers(:david) 146 156 -
activerecord/lib/active_record/associations/association_proxy.rb
old new 73 73 end 74 74 75 75 def inspect 76 reload unlessloaded?76 reload if needs_to_be_loaded? 77 77 @target.inspect 78 78 end 79 79 … … 137 137 def load_target 138 138 return nil unless defined?(@loaded) 139 139 140 if !loaded? and (!@owner.new_record? || foreign_key_present) 141 @target = find_target 142 end 140 @target = find_target if needs_to_be_loaded? 143 141 144 142 @loaded = true 145 143 @target … … 147 145 reset 148 146 end 149 147 148 def needs_to_be_loaded? 149 !loaded? && (!@owner.new_record? || foreign_key_present) 150 end 151 150 152 # Can be overwritten by associations that might have the foreign key available for an association without 151 153 # having the object itself (and still being a new record). Currently, only belongs_to presents this scenario. 152 154 def foreign_key_present