diff options
author | Akira Matsuda <ronnie@dio.jp> | 2015-02-27 12:14:03 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2015-02-28 14:50:13 +0900 |
commit | 243cb81010dbf30ab99d6682a758048bfcb24bc7 (patch) | |
tree | de8cd39b30562991ba691f53c0c58ea8ba405835 /activerecord/lib | |
parent | 3458873642182689e835be8643a50b7634c3e0f5 (diff) | |
download | rails-243cb81010dbf30ab99d6682a758048bfcb24bc7.tar.gz rails-243cb81010dbf30ab99d6682a758048bfcb24bc7.tar.bz2 rails-243cb81010dbf30ab99d6682a758048bfcb24bc7.zip |
Preserve Array#take(n) behaviour of HasManyAssociation
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 82a7c27799..0ba03338f6 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -129,11 +129,11 @@ module ActiveRecord first_nth_or_last(:last, *args) end - def take + def take(n = nil) if loaded? - target.first + n ? target.take(n) : target.first else - scope.take.tap do |record| + scope.take(n).tap do |record| set_inverse_instance record if record.is_a? ActiveRecord::Base end end diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 87e80e88b2..e11c9490b7 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -227,8 +227,8 @@ module ActiveRecord @association.last(*args) end - def take - @association.take + def take(n = nil) + @association.take(n) end # Returns a new object of the collection type that has been instantiated |