diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-01-01 04:33:59 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-01-01 04:33:59 +0900 |
commit | 6ba7adbaa76244e9e592f5672c8411dd0b4e7fce (patch) | |
tree | 7dbe7486207793862f391a7afa42cf1096cb30ba /activerecord/lib/active_record | |
parent | ac0b28883b78999c5605d032eb42fcd842841e6b (diff) | |
download | rails-6ba7adbaa76244e9e592f5672c8411dd0b4e7fce.tar.gz rails-6ba7adbaa76244e9e592f5672c8411dd0b4e7fce.tar.bz2 rails-6ba7adbaa76244e9e592f5672c8411dd0b4e7fce.zip |
Refactor `CollectionAssociation#ids_reader`
Simply we can do `target.pluck(reflection.association_primary_key)` if
`target` is loaded.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 974405e019..9fa8b5d469 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -47,9 +47,7 @@ module ActiveRecord # Implements the ids reader method, e.g. foo.item_ids for Foo.has_many :items def ids_reader if loaded? - load_target.map do |record| - record.send(reflection.association_primary_key) - end + target.pluck(reflection.association_primary_key) else @association_ids ||= ( column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}" |