Skip to content
Browse files

Fix #5563. Should reflect the most recent change to either of associa…

…tion / id.
  • Loading branch information...
1 parent 0f3901e commit 365b8b6db750151b786b0a7ef9e65a6824576f1b @kennyj committed Mar 30, 2012
View
3 activerecord/lib/active_record/associations/association.rb
@@ -132,7 +132,8 @@ def target_scope
# ActiveRecord::RecordNotFound is rescued within the method, and it is
# not reraised. The proxy is \reset and +nil+ is the return value.
def load_target
- @target ||= find_target if find_target?
+ @target = find_target if (@stale_state && stale_target?) || find_target?
+
loaded! unless loaded?
target
rescue ActiveRecord::RecordNotFound
View
11 activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -705,4 +705,15 @@ def test_polymorphic_with_custom_primary_key
assert_equal toy, sponsor.reload.sponsorable
end
+
+ def test_reflect_the_most_recent_change
+ author1, author2 = Author.limit(2)
+ post = Post.new(:title => "foo", :body=> "bar")
+
+ post.author = author1
+ post.author_id = author2.id
+
+ assert post.save
+ assert_equal post.author_id, author2.id
+ end
end

0 comments on commit 365b8b6

Please sign in to comment.
Something went wrong with that request. Please try again.