Create pivot model for user-role mapping


#1

I’m using adonis acl for user - roles - permission mapping. In this structure the mapping between roles - permissions is belongsToMany mapping and a pivot table is generated to store mapping values and i can define pivot model to have any control over the pivot table and i can define hooks, getters etc. by defining

cars () {
return this
.belongsToMany(‘App/Models/Car’)
.pivotModel(‘App/Models/UserCar’)
}

But in User - Roles and User - Permissions mapping it is done by traits in the user modal.

class User extends Model {

static get traits () {
return [
@provider:Adonis/Acl/HasRole’,
@provider:Adonis/Acl/HasPermission’
]
}

}

Here there is no belongsToMany mapping but join tables named role_users and permission_users are created. Now i want to create pivot model for these mapping tables role_users and permission_users to define a hook or getters/setters but i’m not able to do this. Kindly help me to create a pivot model for user-role, user-permission mapping.

Thanks in advance.