I need to join owner model by ownerType
value;
if ownerType == org
, i need to set owner.model
to org
// api/models/Request.js
module.exports = {
attributes: {
product: 'string',
ownerType: {
type: 'string',
enum:['org','person']
},
ownerId:'int',
owner: {
model: ''// model by ownerType
}
}
};`
`// api/models/Org.js
module.exports = {
attributes: {
name: 'string',
requests:{
collection:'request'
}
}
};`
`// api/models/Person.js
module.exports = {
attributes: {
firstName: 'string',
requests:{
collection:'request'
}
}
};
Any right way to do dynamic association? Or it can be done only in controller?