Ruby on Rails中的自动保存选项

时间:2010-06-17 00:26:34

标签: ruby-on-rails activerecord

有没有办法在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!

这可能还是我在错误的树上咆哮?

2 个答案:

答案 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