我正在尝试使用 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],
});
}
不幸的是,当我点击this.get("/users");
http 请求时,我收到一个海市蜃楼错误,我理解但无法修复:
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.
据我所知,我正在传递一个模型数组?请问我该如何解决?