Forum: Ruby on Rails saving second order association with ActiveRecord

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.
525128e48ca2b4c7fb6176ea166fccfd?d=identicon&s=25 Eric G. (gotskill10)
on 2007-01-19 07:57
I was wondering if it was possible to save a given object that has
associations embedded within it.

For example if you have book = {:id=>4,:title=>"hi
there",:pages=>[{:id=>4},{:id=>6}]}, then you could do some thing like

new=Book.new(book)
new.save

and then it would also do a join and save those books as well.

OR

can you do something like

book=Book.find(:first,:include=>"pages")
book.pages[1].creator = "Joe Schmo"
book.save

Could you do something like that as well?
70ca58d0e0e0eabbdb74d177417d09d7?d=identicon&s=25 augustlilleaas@gmail.com (Guest)
on 2007-01-19 16:31
(Received via mailing list)
Yes =D

And if a book has_one :author, you can go @book = Book.find(1) and then
@book.author.new.

On Jan 19, 7:57 am, Aryk Grosz <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.