# Saving a related object

**URL:** <https://www.ruby-forum.com/t/saving-a-related-object/117083>\
**Category:** Rails\
**Created:** [October 12, 2007, 7:57pm UTC](https://www.ruby-forum.com/t/saving-a-related-object/117083 "2007-10-12T19:57:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [October 12, 2007, 7:57pm UTC](https://www.ruby-forum.com/t/saving-a-related-object/117083/1 "2007-10-12T19:57:44Z")

</div>

Hello,

I have two models. A and B. A belongs\_to B (and B has\_one A). I have one  
form  
for creating both an A and a B, so I do:

a = A.new(params[:a])  
a.b = B.new(params[:b])  
if a.save…

and it works as intended, both objects get saved, or none, validation  
happens.  
But then I have the page to edit these objects. So I do:

a = A.find(a\_id)  
…latter on…  
a.attributes = params[:a]  
a.b.attributes = params[:b]  
if a.save…

and there it is where it breaks. b seems to be never saved. I’m not sure  
if it  
is validated or not. What should I do to cascade the saves? or how  
should I  
save these two objects?

## Thank you.

J. Pablo Fernández [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ([http://pupeno.com](http://pupeno.com))

---

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [October 13, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/saving-a-related-object/117083/2 "2007-10-13T14:13:58Z")

</div>

Did you look at

after\_save ?

Maybe you can perform something inside it in the A model
