【发布时间】:2020-06-18 09:18:24
【问题描述】:
我正在尝试使用 Mirage js createList 工具创建属于用户的多个帖子。我已经创建了具有对应关系的模型:
models: {
user: Model.extend({
posts: hasMany(),
}),
post: Model.extend({
user: belongsTo()
})
}
在seeds 方法中,我试图创建一个帖子列表并使用以下代码将它们分配给用户:
seeds(server) {
let posts = server.createList("post", 2);
server.create("user", {
name: "John",
posts: [posts],
});
}
不幸的是,当我在 http 请求中点击 this.get("/users"); 时,我收到一个海市蜃楼错误,我理解但无法修复:
Mirage: You're trying to create a user model and you passed in "model:post(1),model:post(2)" under the posts key, but that key is a HasMany relationship. You must pass in a Collection, PolymorphicCollection, array of Models, or null.
据我所知,我正在传递一个模型数组?请问怎么解决?
【问题讨论】:
标签: javascript ember-cli-mirage miragejs