mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
984 B
50 lines
984 B
6 years ago
|
const Model = require('objection').Model
|
||
|
|
||
|
/**
|
||
|
* Tags model
|
||
|
*/
|
||
|
module.exports = class Tag extends Model {
|
||
|
static get tableName() { return 'tags' }
|
||
|
|
||
|
static get jsonSchema () {
|
||
|
return {
|
||
|
type: 'object',
|
||
|
required: ['tag'],
|
||
|
|
||
|
properties: {
|
||
|
id: {type: 'integer'},
|
||
|
tag: {type: 'string'},
|
||
|
title: {type: 'string'},
|
||
|
|
||
|
createdAt: {type: 'string'},
|
||
|
updatedAt: {type: 'string'}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static get relationMappings() {
|
||
|
return {
|
||
|
pages: {
|
||
|
relation: Model.ManyToManyRelation,
|
||
|
modelClass: require('./pages'),
|
||
|
join: {
|
||
|
from: 'tags.id',
|
||
|
through: {
|
||
|
from: 'pageTags.tagId',
|
||
|
to: 'pageTags.pageId'
|
||
|
},
|
||
|
to: 'pages.id'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$beforeUpdate() {
|
||
|
this.updatedAt = new Date().toISOString()
|
||
|
}
|
||
|
$beforeInsert() {
|
||
|
this.createdAt = new Date().toISOString()
|
||
|
this.updatedAt = new Date().toISOString()
|
||
|
}
|
||
|
}
|