this is just an example, I understand that you would normally have multiple comments, but for the sake of this example, lets assume that we have
following models:
models: {
blogPost: Model.extend({
comment: belongsTo(),
}),
picture: Model.extend({
comment: belongsTo(),
}),
comment: Model.extend({
commentable: belongsTo({ polymorphic: true }),
}),
},
and following factories:
factories: {
blogPost: Factory.extend({
title: "Whatever",
withComment: trait({
comment: association(),
}),
}),
Now when trying to seed server with:
seeds(server) {
server.create("blogPost", "withComment");
}
It does seed it but when checking console.log(server.db.dump());
the commentable is null... commentableId: null
.
Why?
EDIT:
This is a tricky one. I changed
comment: Model.extend({
commentable: belongsTo({ polymorphic: true }),
}),
to:
comment: Model.extend({
blogPost: belongsTo({ polymorphic: true }),
}),
just to see if commentable
part is causing the issue. This time I got a different error:
Mirage: You're using the association() helper on your comment factory for blogPost, which is a polymorphic relationship. This is not currently supported."
So, it is currently not possible to use association()
on polymorphic relationship. I wish this was announced in documentation...
Still, I cannot find a way to seed it even without shorthand association()
.