# Saving parent record before child

**URL:** <https://www.ruby-forum.com/t/saving-parent-record-before-child/165771>\
**Category:** Rails\
**Created:** [April 17, 2009, 10:00am UTC](https://www.ruby-forum.com/t/saving-parent-record-before-child/165771 "2009-04-17T10:00:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 17, 2009, 10:00am UTC](https://www.ruby-forum.com/t/saving-parent-record-before-child/165771/1 "2009-04-17T10:00:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 17, 2009, 10:09am UTC](https://www.ruby-forum.com/t/saving-parent-record-before-child/165771/2 "2009-04-17T10:09:41Z")

</div>

removed\_email\_address@domain.invalid 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.
