Class: ActiveRecord::Associations::HasManyAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/association_collection_tools.rb

Overview

Return the list of IDs in this association without unnecessarily instantiating a bunch of Active Record objects.

Instance Method Summary collapse

Instance Method Details

#idsObject



129
130
131
132
133
134
135
# File 'lib/association_collection_tools.rb', line 129

def ids
  if self.loaded?
    self.map{|x| x.id}
  else
    connection.select_all("SELECT #{@reflection.klass.primary_key} FROM #{@reflection.klass.table_name} WHERE #{@reflection.primary_key_name} = #{@owner.quoted_id}").map!{|x| x[@reflection.klass.primary_key].to_i}
  end
end