# Join table not being populated

**URL:** <https://www.ruby-forum.com/t/join-table-not-being-populated/61823>\
**Category:** Rails\
**Created:** [May 28, 2006, 8:18am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823 "2006-05-28T08:18:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 28, 2006, 8:18am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/1 "2006-05-28T08:18:16Z")

</div>

Hello,  
I have the usual Categories and Products table scenario, mediated by a  
Categories\_Products join table. When I create a new Product and into a  
given Category, I notice that my join table is not being populated.  
Shouldn’t the join Categories\_Products table be populated?  
Thanks,  
gk

---

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 28, 2006, 8:40am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/2 "2006-05-28T08:40:39Z")

</div>

Gene K. wrote:

> I have the usual Categories and Products table scenario, mediated by a  
> Categories\_Products join table. When I create a new Product and into a  
> given Category, I notice that my join table is not being populated.  
> Shouldn’t the join Categories\_Products table be populated?

I assume you’re doing  
category.products.create(…)  
There’s a bug in create so it doesn’t populate the join table. I’m  
working on the bug, hope to have a fix soon. In the mean time, just use  
\<\< like so:  
category.products \<\< Product.create(…)

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 28, 2006, 9:45am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/3 "2006-05-28T09:45:58Z")

</div>

Thanks for your reply. Since the join table has no model, and it has no  
controller of its own, where would I put such a statement? Any  
site/reference where I can learn about it?  
Thanks,  
gk

Josh S. wrote:

> Gene K. wrote:
> 
> > I have the usual Categories and Products table scenario, mediated by a  
> > Categories\_Products join table. When I create a new Product and into a  
> > given Category, I notice that my join table is not being populated.  
> > Shouldn’t the join Categories\_Products table be populated?
> 
> I assume you’re doing  
> category.products.create(…)  
> There’s a bug in create so it doesn’t populate the join table. I’m  
> working on the bug, hope to have a fix soon. In the mean time, just use  
> \<\< like so:  
> category.products \<\< Product.create(…)
> 
> –  
> Josh S.  
> [http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 28, 2006, 10:02am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/4 "2006-05-28T10:02:54Z")

</div>

On 5/28/06, Gene K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for your reply. Since the join table has no model, and it has no  
> controller of its own, where would I put such a statement? Any

Try using the “category.products \<\< Product.create(…)” where you’d  
normally put Product.create(…).

> site/reference where I can learn about it?  
> Thanks,  
> gk

Your question is related to ActiveRecord associations, so:

[http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html](http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html)

Of course, the basic AR docs are also relevant:

[http://api.rubyonrails.com/classes/ActionWebService/Base.html](http://api.rubyonrails.com/classes/ActionWebService/Base.html)

---

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 28, 2006, 10:12am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/5 "2006-05-28T10:12:19Z")

</div>

Error correction: the second link (to AR::Base) is actually

[http://api.rubyonrails.com/classes/ActiveRecord/Base.html](http://api.rubyonrails.com/classes/ActiveRecord/Base.html)

---

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 29, 2006, 6:50am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/6 "2006-05-29T06:50:26Z")

</div>

I got the fix for this issue accepted to the build today. You can read  
about it here:

[http://blog.hasmanythrough.com/articles/2006/05/28/come-on-eileen](http://blog.hasmanythrough.com/articles/2006/05/28/come-on-eileen)

Note that there’s a plugin so you can get the fix if you’re not running  
on trunk.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 29, 2006, 7:29am UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/7 "2006-05-29T07:29:19Z")

</div>

Josh S. wrote:

> I got the fix for this issue accepted to the build today. You can read  
> about it here:
> 
> [http://blog.hasmanythrough.com/articles/2006/05/28/come-on-eileen](http://blog.hasmanythrough.com/articles/2006/05/28/come-on-eileen)
> 
> Note that there’s a plugin so you can get the fix if you’re not running  
> on trunk.
> 
> –  
> Josh S.  
> [http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

Thanks much again!  
gk

---

<div class="post-metadata">

**Author:** ![kublai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kublai](https://www.ruby-forum.com/u/kublai)\
**Post date:** [May 28, 2006, 7:36pm UTC](https://www.ruby-forum.com/t/join-table-not-being-populated/61823/8 "2006-05-28T19:36:04Z")

</div>

Alder G. wrote:

> Error correction: the second link (to AR::Base) is actually
> 
> [Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Base.html)

Thanks!  
gk
