I have a complicated SQL query that aggregates columns using a group_by
.
IndividualOrder.select(SUM(...) as amount, other_fields).group_by("organization.id")
The problem is: I get an ActiveRecord::Relation from IndividualOrder
, which isn't really what the result is conceptually anymore. I'm not entirely sure how to cast it to a new method. If I use arel
to handle it, I still usually would have to go IndividualOrder.arel_table
, and it would still cast to whatever I select.
I just want to take the fields [:amount, :organization, :other]
and be able to interact with them as I would a database backed model that had those values as a table.
So, it's not quite a tableless model (which usually aren't database backed), and it's not an actual model because it's a generated query.
Is this the use case for scenic? I'm stuck with having to navigate around 2 variables that exist within the query that I'm doing via ActiveRecord
.