Grabbing IDs instead of hydrating a model object
For example, if we want to get back a list of tag ids in our Product model to do some processing/munging:
1 2 def tag_ids 3 sql = "SELECT tag_id FROM products_tags WHERE product_id = #{self.id} ORDER BY tag_id ASC" 4 ActiveRecord::Base.connection.select_values(sql).collect! { |x| x.to_i } 5 end
Voila, an array of integers. Much faster, depending on the size of your model object.