Hi, I'd like to use the power of ActiveRecord's associations to build the join section of a query and also be able to add a group section or change the select part.
For example (this doesn't work)
Person.find :all, :include => [:portfolio => :houses], :group => 'people.id', :select => 'people.*, count(*) as house_count, avg(houses.price) as house_avg_price'
Using the :include statement ignores the group and select statements. This is fair enough since you can't do proper eager loading with either of those statements. What I would like is for the :joins option to be able to use the tree syntax of the :include option and create a select using the ActiveRecord associations. The above example would look like this:
Person.find :all, :joins => [:portfolio => :houses], :group => 'people.id', :select => 'people.*, count(*) as house_count, avg(houses.price) as house_avg_price'
Does this make sense?
Cheers, Bonne Eggleston