I have two ActiveRecord classes that point at each other with a "has_and_belongs_to_many" (habtm) relationship using a join table. The join table has an a few additional columns besides the _id columns. For those of you with the Agile Web Dev w/ Rails book, it''s exactly the same setup as the articles<->articles_users<->users example on p240. The habtm relationship is setup fine. I can see the linked data in instances of the objects. The problem, though, is that I can''t update the extra columns in the join table using update_attributes. This is a well documented shortcoming, and the solution everyone talks about is to override the update_attributes code. The code (see the comments @ http://tinyurl.com/ey5qd) starts like so: module ActiveRecord module Associations class HasAndBelongsToManyAssociation def update_attributes(record, join_attributes = {}) The problem is, and here is why I''m writing, that this code isn''t called when you call update_attributes. In fact, if you go and edit the file that defines HasAndBelongsToManyAssociations and you put in a method "foo" and call it, it won''t be called either. Would be grateful for any assistance. -- Posted via http://www.ruby-forum.com/.
Why not use edge rails :though? On 1/24/06, Dan Grigsby <dan-ruby-forum@unpossible.com> wrote:> > I have two ActiveRecord classes that point at each other with a > "has_and_belongs_to_many" (habtm) relationship using a join table. The > join > table has an a few additional columns besides the _id columns. > > For those of you with the Agile Web Dev w/ Rails book, it''s exactly the > same > setup as the articles<->articles_users<->users example on p240. > > The habtm relationship is setup fine. I can see the linked data in > instances of the objects. > > The problem, though, is that I can''t update the extra columns in the > join > table using update_attributes. This is a well documented shortcoming, > and > the solution everyone talks about is to override the update_attributes > code. > > The code (see the comments @ http://tinyurl.com/ey5qd) starts like so: > > module ActiveRecord > module Associations > class HasAndBelongsToManyAssociation > def update_attributes(record, join_attributes = {}) > > The problem is, and here is why I''m writing, that this code isn''t called > when you call update_attributes. In fact, if you go and edit the file > that > defines HasAndBelongsToManyAssociations and you put in a method "foo" > and > call it, it won''t be called either. > > Would be grateful for any assistance. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- First they laugh at you, then they ignore you, then they fight you. Then you win. -- Mahatma Karamchand Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060125/a7a45cd9/attachment.html
http://www.matthewman.net/articles/2006/01/06/rails-activerecord-goes-through On 1/24/06, Leon Leslie <leonleslie@gmail.com> wrote:> > Why not use edge rails :though? > > > On 1/24/06, Dan Grigsby <dan-ruby-forum@unpossible.com> wrote: > > > > I have two ActiveRecord classes that point at each other with a > > "has_and_belongs_to_many" (habtm) relationship using a join table. The > > join > > table has an a few additional columns besides the _id columns. > > > > For those of you with the Agile Web Dev w/ Rails book, it''s exactly the > > same > > setup as the articles<->articles_users<->users example on p240. > > > > The habtm relationship is setup fine. I can see the linked data in > > instances of the objects. > > > > The problem, though, is that I can''t update the extra columns in the > > join > > table using update_attributes. This is a well documented shortcoming, > > and > > the solution everyone talks about is to override the update_attributes > > code. > > > > The code (see the comments @ http://tinyurl.com/ey5qd) starts like so: > > > > module ActiveRecord > > module Associations > > class HasAndBelongsToManyAssociation > > def update_attributes(record, join_attributes = {}) > > > > The problem is, and here is why I''m writing, that this code isn''t called > > when you call update_attributes. In fact, if you go and edit the file > > that > > defines HasAndBelongsToManyAssociations and you put in a method "foo" > > and > > call it, it won''t be called either. > > > > Would be grateful for any assistance. > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > First they laugh at you, then they ignore you, then they fight you. > Then you win. > -- Mahatma Karamchand Gandhi-- First they laugh at you, then they ignore you, then they fight you. Then you win. -- Mahatma Karamchand Gandhi -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060125/a36bcc12/attachment.html