有没有办法在Rails中关闭自动保存?我不希望修改关联以自动保存到数据库UNTIL我在父对象上调用save。
some_parent.some_children << child #should not save, just adds to the association!
some_parent.save #now parent and children are saved!
这可能还是我在错误的树上咆哮?
答案 0 :(得分:3)
我认为这可能足以提供一些帮助。
some_parent.some_children.build({:child_attr1 => 'child_val1'})
some_parent.save # should save the new child as well
答案 1 :(得分:1)
我认为您只需要使用autosave声明some_children关联:false