Problem with has_many through

another active record question :
i’ve got 3 classes :

1/
class Store < ActiveRecord::Base
has_many :store_entries
has_many :store_shipping_countries
end

2/
class StoreShippingCountry < ActiveRecord::Base
belongs_to :store
has_many :store_entries,
:through => :store
end

3/
class StoreEntry < ActiveRecord::Base
belongs_to :store
has_many :store_shipping_countries,
:through => :store
end

in store entry i’m calling store_shipping_countries and here is what
i’ve got in the log file :

store_shipping_countries.* FROM store_shipping_countries INNER JOIN
stores ON store_shipping_countries.store_id = stores.id WHERE
((stores.store_id = 1004))

i don’t understand how it build the WHERE clause “((stores.store_id =
1004))”. it should be (store_entries.id = 1004) !

please help.

Hi Jean-Sébastien,

Aren’t you trying to do this instead?

1/
class Store < ActiveRecord::Base
has_many :store_shipping_countries
has_many :store_entries, :through => :store_shipping_countries
end

2/
class StoreShippingCountry < ActiveRecord::Base
belongs_to :store
has_many :store_entries
end

3/
class StoreEntry < ActiveRecord::Base
belongs_to :StoreShippingCountry
end