That's right, I think that you really do not need the joins clause in rails 3. If you use include and where, Arel will do the hard work for you.
I tested this (although I used a different set of models (and attributes) than yours) using models with the same association location, and I think this should work:
in models /user.rb:
scope :with_group_and descriptions, lambda { |group_id| includes(:groups, :descriptions).where(:groups => { :id => group_id }, :descriptions => { :group_id => group_id }) }
Then in the controller you call:
@users = User.with_group_and_descriptions(params[:id])
Finally, in the view, you can:
@users.each do |user| user.name user.descriptions.each do |desc| desc.content
If I understood correctly, this should only make 2 dB of calls. One to get the list of user_ids, and the second to get data about the user, group and description, and even though you call the method of describing user objects, which usually contains all the descriptions (and not just those that belong to a specific group), since you already filled the union rails, you wonβt be able to capture all the associations again when you call user.descriptions , instead it will simply display the ones you pulled from the database using the description of .group_id, where is the item. Calling user.descriptions(true) will reload the descriptions, which will return an array of all description associations for the user.
source share