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 -- Posted via http://www.ruby-forum.com/.
Gene Kahn 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 Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.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 Susser wrote:> Gene Kahn 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 Susser > http://blog.hasmanythrough.com-- Posted via http://www.ruby-forum.com/.
On 5/28/06, Gene Kahn <kublaikhan55@hotmail.com> 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? AnyTry using the "category.products << Product.create(...)" where you''d normally put Product.create(...).> site/reference where I can learn about it? > Thanks, > gkYour 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 -- -Alder
Error correction: the second link (to AR::Base) is actually http://api.rubyonrails.com/classes/ActiveRecord/Base.html -- -Alder
Alder Green wrote:> Error correction: the second link (to AR::Base) is actually > > http://api.rubyonrails.com/classes/ActiveRecord/Base.htmlThanks! gk -- Posted via http://www.ruby-forum.com/.
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 Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
Josh Susser 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 Susser > http://blog.hasmanythrough.comThanks much again! gk -- Posted via http://www.ruby-forum.com/.