From 6ba7adbaa76244e9e592f5672c8411dd0b4e7fce Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 1 Jan 2017 04:33:59 +0900 Subject: Refactor `CollectionAssociation#ids_reader` Simply we can do `target.pluck(reflection.association_primary_key)` if `target` is loaded. --- activerecord/lib/active_record/associations/collection_association.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/associations') 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}" -- cgit v1.2.3