[英]autosave options in Ruby on Rails
Is there a way to turn OFF autosave in Rails? 有没有办法在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
我认为您只需要声明带有autosave的some_children关联:false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.