开发者

autosave options in Ruby on Rails

开发者 https://www.devze.com 2023-01-03 14:06 出处:网络
Is there a way to turn OFF autosave in Rails?I don\'t want modifications to an association to automatically save to the database UNTIL I call save on the parent object.

Is there a way to turn OFF autosave in Rails? I don't want modifications to an association to automatically save to the database UNTIL I call save on the parent object.

some_parent.some_children << child #should not save, just adds to the association!

some_parent.save #now parent and children 开发者_如何学运维are saved!

It this possible or am I barking up the wrong tree?


I think this may be close enough to provide some help.

some_parent.some_children.build({:child_attr1 => 'child_val1'})
some_parent.save # should save the new child as well


I think you simply need to declare the some_children association with autosave: false

0

精彩评论

暂无评论...
验证码 换一张
取 消