AR update and save child based on change in parent

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs