aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2013-09-26 14:55:10 -0400
committerArthur Neves <arthurnn@gmail.com>2013-09-26 14:55:10 -0400
commitfed6ac9c66e87d120098b3a4ffb15699d0ee6863 (patch)
tree370c66237060ff4a9c8f434e0d040915b047e0bb /activerecord/lib/active_record/associations
parente82cecae351a514c87a05eeeabf55f6bdfb0f280 (diff)
downloadrails-fed6ac9c66e87d120098b3a4ffb15699d0ee6863.tar.gz
rails-fed6ac9c66e87d120098b3a4ffb15699d0ee6863.tar.bz2
rails-fed6ac9c66e87d120098b3a4ffb15699d0ee6863.zip
fix inverse_of when find_or_initialize_by_*
inverse_of relation was not being set when calling find_or_initialize_by_ and the entry was found on the db.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 416a5823c6..62cdb1ea87 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -77,10 +77,12 @@ module ActiveRecord
def method_missing(method, *args, &block)
match = DynamicFinderMatch.match(method)
if match && match.instantiator?
- send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r|
- proxy_association.send :set_owner_attributes, r
- proxy_association.send :add_to_target, r
- yield(r) if block_given?
+ send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |record|
+ proxy_association.send :set_owner_attributes, record
+ proxy_association.send :add_to_target, record
+ yield(record) if block_given?
+ end.tap do |record|
+ proxy_association.send :set_inverse_instance, record
end
elsif target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))