Multiple has_many through join table appears multiple times

Hi All,

I am trying to configure my models to generate sql like this:

select *
from location
   inner join sales
   inner join product
   inner join calendar

Currently the models all have this:

class Location...
has_many :sales :foreign_key => "location_id"
has_many :products :through => :sales
has_many :calendars :through => :sales

class Product...
has_many :sales :foreign_key => "product_id"
has_many :calendars :through => :sales
has_many :locations :through => :sales

class Calendar...
has_many :sales :foreign_key => "calendar_id"
has_many :products :through => :sales
has_many :locations :through => :sales

class Sales...
belongs_to :calendar
belongs_to :product
belongs_to :location

In my controller I have this:

Location.find (
  :all,
  :select => "calendar.year, location.country, product.name,
sales.amount"
  :joins => [:products, :calendars]
)

The issue is I get sql like this where the sales table appears twice
(re-written for brevatiy)

select *
from location
   inner join sales
   inner join product
   inner join sales_calendar
   inner join calendar on sales_calendar.. = calendar....

What must I change to only get the sales table there once i.e.

select *
from location
   inner join sales
   inner join product
   inner join calendar

Thanks

ended up using Sales.find(... which generated the correct sql