I absolutely despise ActiveRecord because it makes
non-trivial aggregates a pain to write
I'm a SQL guy at heart.I certainly agree with you... I loathe writing any non-trivial query in ActiveRecord's query builder.
However, I find ActiveRecord does a really good job of getting out of the way when I deem it easier to write some raw SQL.
Generally do one of two things.
If I have a really big nasty query, I'll implement it as a (standard or materialized) database view. I may query it directly or map a model to it.
Or, I'll just use `MyModel.find_by_sql("blahblahblah")` which happily accepts my handwritten SQL.
I don't have a link handy but DHH stated ages ago that the ability to do stuff like that was an explicit goal of ActiveRecord.