mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
b03ecd9ebc
Refs #2170 This removes the circular dependency problem from our models thanks to https://github.com/tgriesser/bookshelf/issues/181 - add the registry plugin - switch all models and collections to be registered - switch relationships to be defined using a string, which calls from the registry
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
var ghostBookshelf = require('./base'),
|
|
|
|
Accesstoken,
|
|
Accesstokens;
|
|
|
|
Accesstoken = ghostBookshelf.Model.extend({
|
|
|
|
tableName: 'accesstokens',
|
|
|
|
user: function () {
|
|
return this.belongsTo('User');
|
|
},
|
|
|
|
client: function () {
|
|
return this.belongsTo('Client');
|
|
},
|
|
|
|
// override for base function since we don't have
|
|
// a created_by field for sessions
|
|
creating: function (newObj, attr, options) {
|
|
/*jshint unused:false*/
|
|
},
|
|
|
|
// override for base function since we don't have
|
|
// a updated_by field for sessions
|
|
saving: function (newObj, attr, options) {
|
|
/*jshint unused:false*/
|
|
// Remove any properties which don't belong on the model
|
|
this.attributes = this.pick(this.permittedAttributes());
|
|
}
|
|
|
|
}, {
|
|
destroyAllExpired: function (options) {
|
|
options = this.filterOptions(options, 'destroyAll');
|
|
return ghostBookshelf.Collection.forge([], {model: this})
|
|
.query('where', 'expires', '<', Date.now())
|
|
.fetch()
|
|
.then(function (collection) {
|
|
collection.invokeThen('destroy', options);
|
|
});
|
|
}
|
|
});
|
|
|
|
Accesstokens = ghostBookshelf.Collection.extend({
|
|
model: Accesstoken
|
|
});
|
|
|
|
module.exports = {
|
|
Accesstoken: ghostBookshelf.model('Accesstoken', Accesstoken),
|
|
Accesstokens: ghostBookshelf.collection('Accesstokens', Accesstokens)
|
|
}; |