Class: ActiveRecord::Associations::HasManyAssociation
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::HasManyAssociation
- 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
#ids ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/association_collection_tools.rb', line 135 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 |