# Problem with has\_many through

**URL:** <https://www.ruby-forum.com/t/problem-with-has-many-through/103304>\
**Category:** Rails\
**Created:** [May 4, 2007, 12:48am UTC](https://www.ruby-forum.com/t/problem-with-has-many-through/103304 "2007-05-04T00:48:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [May 4, 2007, 12:48am UTC](https://www.ruby-forum.com/t/problem-with-has-many-through/103304/1 "2007-05-04T00:48:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/49beb7/32.png) [@jney](https://www.ruby-forum.com/u/jney)\
**Post date:** [May 4, 2007, 1:10am UTC](https://www.ruby-forum.com/t/problem-with-has-many-through/103304/2 "2007-05-04T01:10:20Z")

</div>

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
