diff options
author | Michal Cichra <michal@o2h.cz> | 2013-03-29 10:03:56 +0100 |
---|---|---|
committer | Michal Cichra <michal@o2h.cz> | 2013-04-01 15:11:07 +0200 |
commit | 448381593edf0b87e3afd4945bd13650a7483b17 (patch) | |
tree | 552fffafdfa45c3014aec1fc5315d5f01ff8a44d /activerecord/lib/active_record | |
parent | 56edecbf24c7c05957ee64b25b2d3c957afca632 (diff) | |
download | rails-448381593edf0b87e3afd4945bd13650a7483b17.tar.gz rails-448381593edf0b87e3afd4945bd13650a7483b17.tar.bz2 rails-448381593edf0b87e3afd4945bd13650a7483b17.zip |
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
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 4c4b0f08e5..6578a9096b 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -235,6 +235,7 @@ module ActiveRecord skip_assign = [reflection.foreign_key, reflection.type].compact attributes = create_scope.except(*(record.changed - skip_assign)) record.assign_attributes(attributes) + set_inverse_instance(record) end end end |