Forum: Ruby on Rails has_many.collection<<obj doesn't set attributes?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joe (Guest)
on 2006-03-14 00:12
I tried:

@item.stuff<<thing

and in thing I have:

def stuff_id=(value)
  # remember old stuff_id cuz Rails has lousy trigger equivalent
  logger.debug 'set stuff_id called'
end

And apparently stuff_id doesn't get called, but the fk is changed
directly in the database? I'm about to abandon trying to do trigger
related stuff in Rails and go back to putting it in the database. Trying
to do OLD/NEW trigger equivalents in Rails sucks.

Joe
Jonathan V. (Guest)
on 2006-03-14 00:20
(Received via mailing list)
For stuff_id= to be called you need to do @item.stuff_id = thing.id. I
assume you're using belongs_to? You can also use the association
callbacks:

http://api.rubyonrails.org/classes/ActiveRecord/Ag...

-Jonathan.
This topic is locked and can not be replied to.