2013-09-24 12:46:30 +02:00
|
|
|
var User = require('./user').User,
|
|
|
|
Permission = require('./permission').Permission,
|
2013-09-22 18:20:08 -04:00
|
|
|
ghostBookshelf = require('./base'),
|
2014-02-19 14:57:26 +01:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
Role,
|
|
|
|
Roles;
|
|
|
|
|
2013-09-22 18:20:08 -04:00
|
|
|
Role = ghostBookshelf.Model.extend({
|
2013-06-25 12:43:15 +01:00
|
|
|
|
2013-09-14 20:01:46 +01:00
|
|
|
tableName: 'roles',
|
2013-08-25 11:49:31 +01:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
users: function () {
|
|
|
|
return this.belongsToMany(User);
|
|
|
|
},
|
|
|
|
|
|
|
|
permissions: function () {
|
|
|
|
return this.belongsToMany(Permission);
|
|
|
|
}
|
2014-05-05 21:45:08 -04:00
|
|
|
}, {
|
|
|
|
/**
|
|
|
|
* Returns an array of keys permitted in a method's `options` hash, depending on the current method.
|
|
|
|
* @param {String} methodName The name of the method to check valid options for.
|
|
|
|
* @return {Array} Keys allowed in the `options` hash of the model's method.
|
|
|
|
*/
|
|
|
|
permittedOptions: function (methodName) {
|
|
|
|
var options = ghostBookshelf.Model.permittedOptions(),
|
|
|
|
|
|
|
|
// whitelists for the `options` hash argument on methods, by method name.
|
|
|
|
// these are the only options that can be passed to Bookshelf / Knex.
|
|
|
|
validOptions = {
|
|
|
|
findOne: ['withRelated'],
|
|
|
|
add: ['user']
|
|
|
|
};
|
|
|
|
|
|
|
|
if (validOptions[methodName]) {
|
|
|
|
options = options.concat(validOptions[methodName]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
2013-06-25 12:43:15 +01:00
|
|
|
});
|
|
|
|
|
2013-09-22 18:20:08 -04:00
|
|
|
Roles = ghostBookshelf.Collection.extend({
|
2013-06-25 12:43:15 +01:00
|
|
|
model: Role
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Role: Role,
|
|
|
|
Roles: Roles
|
|
|
|
};
|