aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-01 14:27:45 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-01 14:27:57 -0200
commitc368b660be2433e291a2c87b3eb3de3dfac397ef (patch)
treea10d3df18ce149e294c5f1b221999fd8b625c7b9 /activerecord/lib
parentd37d40b2d702e9ff1461a3571f7f4d7ec52c2a2a (diff)
downloadrails-c368b660be2433e291a2c87b3eb3de3dfac397ef.tar.gz
rails-c368b660be2433e291a2c87b3eb3de3dfac397ef.tar.bz2
rails-c368b660be2433e291a2c87b3eb3de3dfac397ef.zip
Ensure calling first/last with options correctly set inverse association
Also related to #8087. Thanks @al2o3cr.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 43701708a4..65e882867e 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -571,7 +571,9 @@ module ActiveRecord
args.shift if args.first.is_a?(Hash) && args.first.empty?
collection = fetch_first_or_last_using_find?(args) ? scoped : load_target
- collection.send(type, *args).tap { |it| set_inverse_instance it if args.blank? }
+ collection.send(type, *args).tap do |record|
+ set_inverse_instance record if record.is_a? ActiveRecord::Base
+ end
end
end
end