On Mar 20, 3:30 pm, Fabrice Fabrisss <li...@ruby-forum.com> wrote:
> I'm trying this but it does not work (the value is not updated): > > account = Account.new > transaction.splits.first.account = account > # error: prints the old value of account > puts transaction.splits.first.account > > Do you have any idea ? Do I need to create a new Split and delete the > old one or is it possible to update the existing one ? If the collection (in this case transaction.splits) isn't loaded then foo.first (and foo.last) will fetch just that one row from the database. The way it's implemented, foo.first returns a fresh object each time, so transaction.splits.first.account = account does assign account to that split, however when you call transaction.splits.first.account it's fetching a fresh copy of that split. if you did foo = transaction.splits.first; foo.account = account then you'd be able to see that the assignment did actually happen Fred > > Thank you for your help, > > Fabrice > > -- > 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.