Join table not being populated

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

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

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

On 5/28/06, Gene K. [email protected] 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

Of course, the basic AR docs are also relevant:

http://api.rubyonrails.com/classes/ActionWebService/Base.html

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

http://api.rubyonrails.com/classes/ActiveRecord/Base.html

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

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

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

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

Thanks much again!
gk

Alder G. wrote:

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

http://api.rubyonrails.com/classes/ActiveRecord/Base.html

Thanks!
gk