Is it possible to get ActiveRecord to run a query and return an array
of only the ids of the rows that matched? It seems to insist on giving
me back an array of objects, even if I specify “:select => ‘id’” as
part of my find(). I don’t want to have to loop over the objects
getting all the ids if I don’t have to. Can’t AR be coaxed into
returning ids and only ids?
I’ve pored over documentation and searched the web and I haven’t
really come up with much. Thought I’d try you all.
really come up with much. Thought I’d try you all.
You’ll need to drop back to the raw adapter for a custom query. #find
is only interested in dealing with ActiveRecord instances.
Foo.connection.select_values “SELECT id FROM foos …”