aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-01 13:14:58 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-01 13:50:56 -0200
commitd37d40b2d702e9ff1461a3571f7f4d7ec52c2a2a (patch)
tree7fb38ee09914b73ca04a5d975e633df586976480 /activerecord/lib
parentf32f150e45f3dc3ccbd0adc1c91e6144b3cf1384 (diff)
downloadrails-d37d40b2d702e9ff1461a3571f7f4d7ec52c2a2a.tar.gz
rails-d37d40b2d702e9ff1461a3571f7f4d7ec52c2a2a.tar.bz2
rails-d37d40b2d702e9ff1461a3571f7f4d7ec52c2a2a.zip
Fix issue with collection associations and first(n)/last(n)
When calling first(n) or last(n) in a collection, Active Record was improperly trying to set the inverse of instance in case that option existed. This change was introduced by fdf4eae506fa9895e831f569bed3c4aa6a999a22. In such cases we don't need to do that "manually", since the way collection will be loaded will already handle that, so we just skip setting the inverse association when any argument is given to first(n)/last(n). The test included ensures that these scenarios will have the inverse of instance set properly. Fixes #8087, Closes #8094.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 2c852f6efc..43701708a4 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -571,7 +571,7 @@ 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 }
+ collection.send(type, *args).tap { |it| set_inverse_instance it if args.blank? }
end
end
end