# Has\_many :through habtm

**URL:** <https://www.ruby-forum.com/t/has-many-through-habtm/171841>\
**Category:** Rails\
**Created:** [July 10, 2009, 12:43am UTC](https://www.ruby-forum.com/t/has-many-through-habtm/171841 "2009-07-10T00:43:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![slavix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@slavix](https://www.ruby-forum.com/u/slavix)\
**Post date:** [July 10, 2009, 12:43am UTC](https://www.ruby-forum.com/t/has-many-through-habtm/171841/1 "2009-07-10T00:43:12Z")

</div>

Here is my setup:

class Product \< ActiveRecord::Base  
belongs\_to :catalog  
has\_and\_belongs\_to\_many :product\_groups  
end

class ProductGroup \< ActiveRecord::Base  
belongs\_to :catalog  
has\_and\_belongs\_to\_many :products  
end

class Catalog \< ActiveRecord::Base  
has\_many :product\_groups  
has\_many :products, :through =\> :product\_groups  
end

I get:  
Invalid source reflection macro :has\_and\_belongs\_to\_many for  
has\_many :products, :through =\> :product\_groups. Use :source to  
specify the source reflection.

* * *

I have seen a few threads with posts asking this question, but found  
no suitable solution or workaround…  
any ideas please.

---

<div class="post-metadata">

**Author:** ![slavix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@slavix](https://www.ruby-forum.com/u/slavix)\
**Post date:** [July 10, 2009, 7:17pm UTC](https://www.ruby-forum.com/t/has-many-through-habtm/171841/2 "2009-07-10T19:17:30Z")

</div>

As written, there’s no direct way to do this association in Rails. But  
wouldn’t it be sufficient to use a plain has\_many :products in  
Catalog? You’ve got a corresponding belongs\_to in Product…

–Matt J.

---

<div class="post-metadata">

**Author:** ![slavix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@slavix](https://www.ruby-forum.com/u/slavix)\
**Post date:** [July 10, 2009, 8:08pm UTC](https://www.ruby-forum.com/t/has-many-through-habtm/171841/3 "2009-07-10T20:08:19Z")

</div>

yeah, I think it is sufficient. thanks.
