-
Couldn't load subscription status.
- Fork 1.2k
Closed
Description
I need to define relation between models which use Mixins, but when I console.log(app.models.role), I cannot get the Model. It is a good work flow that Mixins is happened under the ModelBuilder, but I guess that Mixins is defined before the ModelBuilder.
So how can I get the ModelBuilder in mixins?
module.exports = function (Model, option = {}) {
Model.getApp((err, app) => {
console.log(app.models.role); // it is undefined
//Model.hasMany(app.models.role, {as: 'roles', foreignKey: `${Model.modelName}Id`});
Model.role = function (role, cb) {
app.models.role.create(role).then((createdRole) => { // it can get in remote method
cb(null, createdRole);
console.log(Model.modelName);
}).then(()=>{
}).catch((err)=> {
cb(err, null);
})
};
Model.remoteMethod(
'role', {
description: 'Create a role for this Model.',
http: {path: '/authorization/role', verb: 'post'},
accepts: {arg: 'role', type: 'role', http: {source: 'body'}},
returns: {arg: 'role', type: 'role'}
}
);
})
};Metadata
Metadata
Assignees
Labels
No labels