Hi, I am trying to find a way tp update attributes in a habtm association. I am trying to use the code from ticket #2462, but as my association_class_primary_key_name seems to be empty the generated sql code is corrupt. I hope thats not a problem of my model that this variable is empty. What would you recommend to update those attributes (rails 1.1) THANKS!!! -- Posted via http://www.ruby-forum.com/.
Henrik Badekow wrote:> Hi, > > I am trying to find a way tp update attributes in a habtm association. I > am trying to use the code from ticket #2462, but as my > association_class_primary_key_name seems to be empty the generated sql > code is corrupt. I hope thats not a problem of my model that this > variable is empty. > What would you recommend to update those attributes (rails 1.1) > > THANKS!!!Could you post the code you''re using? Thanks, Adam -- Posted via http://www.ruby-forum.com/.
Henrik Badekow wrote:> I am trying to find a way tp update attributes in a habtm association. I > am trying to use the code from ticket #2462, but as my > association_class_primary_key_name seems to be empty the generated sql > code is corrupt. I hope thats not a problem of my model that this > variable is empty. > What would you recommend to update those attributes (rails 1.1)There is no recommended way to update attributes on a habtm association. In fact, rich associations (habtm with attributes) have been deprecated and won''t be supported at all come 2.0 release. Use a join model (has_many :through) instead. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
Brian V. Hughes
2006-Apr-05 18:46 UTC
[Rails] Re: Updating attributes in HABTM association
Josh Susser wrote:> There is no recommended way to update attributes on a habtm association. > In fact, rich associations (habtm with attributes) have been deprecated > and won''t be supported at all come 2.0 release. Use a join model > (has_many :through) instead.Correct me if I''m wrong, but these are technically called "polymorphic joins" aren''t they? I would recommend we try to use the right terms when we can, so that hopefully everyone is on the same page. Saying just "use a join model" easily means more than one thing, just in a Rails context, doesn''t it? -Brian
Brian V. Hughes wrote:> Josh Susser wrote: >> There is no recommended way to update attributes on a habtm association. >> In fact, rich associations (habtm with attributes) have been deprecated >> and won''t be supported at all come 2.0 release. Use a join model >> (has_many :through) instead. > > Correct me if I''m wrong, but these are technically called "polymorphic > joins" > aren''t they? I would recommend we try to use the right terms when we > can, so > that hopefully everyone is on the same page. Saying just "use a join > model" > easily means more than one thing, just in a Rails context, doesn''t it?Brian, I don''t think Henrik was talking about polymorphism. The usual habtm join table has nothing to do with polymorphism, and I''m not sure how to make it work with polymorphic associations anyway. I''m pretty sure I was using the right terminology. In Rails parlance a "join model" is a join table that has been promoted to full model status by adding a primary key and probably other attribute fields as well. It also has a Model class, which habtm join tables don''t, so its table name corresponds to its model name in the usual fashion, rather than being constructed from names of the tables it is joining. You can use polymorphic associations in a join model, but it gets tricky. I just blogged about that a couple days ago in fact. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
Brian V. Hughes
2006-Apr-05 20:32 UTC
[Rails] Re: Updating attributes in HABTM association
Josh Susser wrote:> Brian, I don''t think Henrik was talking about polymorphism. The usual > habtm join table has nothing to do with polymorphism, and I''m not sure > how to make it work with polymorphic associations anyway.Hmm... OK. I thought that the has_many :through designation is what signified a polymorphic join. Obviously, I have that wrong. :)> I''m pretty sure I was using the right terminology. In Rails parlance a > "join model" is a join table that has been promoted to full model status > by adding a primary key and probably other attribute fields as well. It > also has a Model class, which habtm join tables don''t, so its table name > corresponds to its model name in the usual fashion, rather than being > constructed from names of the tables it is joining.Sure. I''m willing to go with that. Like I said, the real goal of my email was to make sure we''re all using the same (or mostly the same) vocab, especially when talking about some of the more involved Rails concepts/features.> You can use polymorphic associations in a join model, but it gets > tricky. I just blogged about that a couple days ago in fact.Well, I''ll definitely need to check out that post so I can figure out what the hell I thought I was talking about! ;-> -Brian