我在服务器上有一个如下所示的数据模型:
recipes : {
<recipe ID> : {
ingredients : [
{
count: 2,
ingredient: <ingredient ID>
},
{
count: 4,
ingredient: <ingredient ID>
}
]
}
},
ingredients : {
<Ingredient ID> : {...},
<Ingredient ID> : {...}
}
我希望能够将配方中的成分 ID 用作完整的成分模型对象,但我想不出最好的方法。我的服务器不支持包含。我是否在自定义序列化程序中拦截它,然后使用 store.findRecord?或者有没有更有效的方法来设置我的模型来支持这一点?我一直无法找到将配料列表作为模型的方法,因为配料列表没有关联的 ID,所以我一直在配方模型上使用 @attr 将其视为只读对象。