Q:

How to query the associations of an association

I want to do the following to get a list of all the reviews for a business:
@business.professionals.reviews

I am not concerned about which professional the reviews belong to, but I want the reviews returned in the same format as professionals would be returned in @business.professionals
In my example, businesses have many professionals, and professionals have many reviews.

A:

Add this to your business model
class Business < ActiveRecord::Base
  has_many :professionals
  has_many :visible_reviews, :through => :professionals, :class_name => "Review", :source => :reviews :conditions => ['prefessionals.reviews_visible = ?',true]
  has_many :reviews, :through => :professionals
end

And now you can get all the reviews of all professionals using
@business.visible_reviews

