From 448381593edf0b87e3afd4945bd13650a7483b17 Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Fri, 29 Mar 2013 10:03:56 +0100 Subject: fix inverse_of association in block of new child This fixes inconsistency when building children of association which has inverse_of set properly. When creating new association object with a block: parent.association.build do |child| child.parent.equal?(parent) # false end So the block the `child.parent` did not point to the same object. But when the object is created it points to same instance: child = parent.association.build child.parent.equal?(parent) # true --- activerecord/CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activerecord/CHANGELOG.md') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 0c8c8c006e..b4f14c3cc8 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -388,6 +388,23 @@ # This will expand the order :name to "authors".name. Author.joins(:books).where('books.published = 1').order(:name) +* Fix associations with `:inverse_of` option when building association + with a block. Inside the block the parent object was different then + after the block. + + Example: + + parent.association.build do |child| + child.parent.equal?(parent) # false + end + + # vs + + child = parent.association.build + child.parent.equal?(parent) # true + + *Michal Cichra* + ## Rails 4.0.0.beta1 (February 25, 2013) ## -- cgit v1.2.3