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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-19 10:11 UTC
Re: saving second order association with ActiveRecord
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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? > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---