Forum: Ruby on Rails Saving habtm relationships and Rails 1.0

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.
Jennyw J. (Guest)
on 2006-01-12 20:44
(Received via mailing list)
I know there's a problem saving has_and_belongs_to_many relationships w/
Rails 1.0 in that only the first association is saved
(http://dev.rubyonrails.org/ticket/3213).

What are people doing about this? I guess I could move to using the
trunk release, but I'm hesitant because that might introduce a bunch of
unknowns.

Is there a workaround?  For example, a way to explicitly saves
assocations?

Thanks!

Jen
Sean H. (Guest)
on 2006-01-30 20:20
(Received via mailing list)
I've been saving the associated object whenever I add something.  This
is terribly inefficient, but I haven't found a consensus on the
"right" way to do it.

# Set up the staff object, and then...
default_entitlements = %w(this that the_other_thing)
staff.save
default_entitlements.each { |e|
  staff.entitlements << Entitlement.find_by_code(e)
  staff.save
}

Not great, but it works.
This topic is locked and can not be replied to.