Forum: Ruby on Rails Saving parent record before child

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.
B0da3943a38e73e17377581149998ddd?d=identicon&s=25 josh.rachner@gmail.com (Guest)
on 2009-04-17 10:00
(Received via mailing list)
I am on Rails 2.2 and want to save an artist object with a child
attribute called artist_mood_concepts.  I can update fine but when I
do an @artist.save, it gives me an error about saving the parent
before the child (which makes perfect sense).  What is the easiest way
to solve the problem?  after_update?

Thanks,

Josh
82b09b041448e75d040587fa76f240c1?d=identicon&s=25 Shaun Keller (akira)
on 2009-04-17 10:09
josh.rachner@gmail.com wrote:
> I am on Rails 2.2 and want to save an artist object with a child
> attribute called artist_mood_concepts.  I can update fine but when I
> do an @artist.save, it gives me an error about saving the parent
> before the child (which makes perfect sense).  What is the easiest way
> to solve the problem?  after_update?
>
> Thanks,
>
> Josh

Save the child in the before_save method of the parent, maybe?  Or if it
should be the other way round, do it in after_save.
This topic is locked and can not be replied to.