Reputation: 1499
I have a Parent object, and it has a Child object as a has_many association.
i get the first child:
s = Parent.first str = s.children.first
and change it:
str.remarks = "something"
now, i would expect s.save to save the child too, but it doesn't. i need to explicitly call str.save, which is bad (because its not in a transaction, and its also ugly).
i've tried marking the relations with :autosave=>true (on both sides) but it does nothing.
what's the standard way of solving this?
i'm working in ROR4, ruby 2.0, if it matters.
Thanks.
Upvotes: 0
Views: 308
Reputation: 7339
In your example, s
is not aware of the temporary changes you're making to the record, they are stored in str
. If you want this to work instead try
s = Parent.first
s.children.first.remarks = "something"
s.save
Upvotes: 1