I'm looking for an easy/fast way of getting an array of ids from a Active Record relation.
Currently i have:
product_ids = Product.select(:id).where(:colour => 'blue').all.map{|p|p.id}
But that's messy and requires a map..
Something like this would be cooler:
product_ids = Product.where(:colour => 'blue').ids
Any ideas?
Thanks :)
map{|p| p.id}can you writemap(&:id). This is true for all enumerators (each,any?,select,rejectetc.), and will call the symbol on each object it loops through.map(&:id)just had a mental blank when writing this up :P