I need to pull aggregated columns from my database in a way that's unique to this page, crosses several models, and is expensive to aggregate in memory on a page that already has performance concerns. As a result, I want to make a hand-written SQL query to the database and return a bunch of simple objects (like hashes, or structs) which I can then dole out to the existing objects that consume this information. ActiveRecord::Base.connection.select_all is perfect for what I want.
My SQL string takes an array of ids:
WHERE entry.task_id IN (#{@project.tasks.id})
but this doesn't work because it returns a wrapped array, and connection.quote returns a bulleted list for some reason. What would be the best way to get the information I want? Should I manually strip off the [ and ]? Is there a handy, accessible function like sanitize_sql_array that'll do the trick? Should I never be calling select_all as part of normal operation?
This appears to have been easier in the past, but most of the methods I would use have been protected (including sanitize_sql_array). Rails really wants me to use ActiveRecord query methods, it seems.