# AR update and save child based on change in parent

**URL:** <https://www.ruby-forum.com/t/ar-update-and-save-child-based-on-change-in-parent/175932>\
**Category:** Rails\
**Created:** [September 23, 2009, 12:41am UTC](https://www.ruby-forum.com/t/ar-update-and-save-child-based-on-change-in-parent/175932 "2009-09-23T00:41:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [September 23, 2009, 12:41am UTC](https://www.ruby-forum.com/t/ar-update-and-save-child-based-on-change-in-parent/175932/1 "2009-09-23T00:41:18Z")

</div>

I thought this would be straightforward, but I’m missing something

class User \< AR::Base  
has\_one :profile, :dependent =\> :destroy  
end

class Profile \< AR::Base  
belongs\_to :user  
end

Based on a field change in User, I want to update and save some values  
in Profile.

So, I have this in User:

def after\_validation\_on\_update  
if self.userType\_changed?  
self.some\_local\_field = ‘’ # this works  
self.profile.field\_x = ‘’ # this not being changed  
self.profile.save # needed?  
end  
end

The fields in User (self) are being updated just fine. But I can’t seem  
to force the changes to fields in User.profile.

Stopping at the gas station for directions…

Thx

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [September 23, 2009, 1:06am UTC](https://www.ruby-forum.com/t/ar-update-and-save-child-based-on-change-in-parent/175932/2 "2009-09-23T01:06:13Z")

</div>

Greg W. wrote:

> I thought this would be straightforward, but I’m missing something

Oh brother. I did it again. Figured it out. A validation prevents me  
from me emptying that field, so the save was being rejected.

– gw
