【发布时间】:2010-12-31 07:21:20
【问题描述】:
也许我不知道如何询问/搜索这个特定的东西,但基本上我想在创建父对象时创建一些关联模型......假设我有以下情况:
我有一个 Recipe has_many Ingredient 模型...有没有办法一次制作它们,例如这是我的种子任务的一部分:
Recipe.create({
:title => 'apple pie',
:description => 'just apple pie',
:ingredients => {
[0] => {:title => 'apples'},
[1] => {:title => 'sugar'},
[2] => {:title => 'pie crust'}
}
})
或者我完全疯了?必须有某种类似的方法来执行此操作,无需创建父模型,然后创建所有子模型......等等。
【问题讨论】:
标签: ruby-on-rails nested-attributes