I have two loopback models, say Product
and Service
. They are related to a parent model Asset
. The Asset
has an AssetType
which says if the current object is a Product
or a Service
. How do I model the entity relationships for this case?
Use polymorphic relations https://loopback.io/doc/en/lb3/Polymorphic-relations.html
"parent": {
"type": "belongsTo",
"polymorphic": {
"foreignKey": "parentId",
"discriminator": "parentType"
}
}