2010-06-17 62 views
2

有没有办法在Rails中关闭自动保存?我不想修改关联自动保存到数据库,直到我调用保存父对象。Ruby on Rails自动保存选项

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

some_parent.save #now parent and children are saved! 

这是可能的还是我吠叫错了树?

+0

的''<<对关联运算符是调皮。如果父母被保存,它将保存孩子,但如果父母没有保存则不保存。 – 2013-04-17 16:32:22

回答

3

我认为这可能足够接近以提供一些帮助。

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

我认为你只需要声明一个带有自动保存的some_children协会:假