12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- const Model = require('objection').Model
- /**
- * Pages model
- */
- module.exports = class Page extends Model {
- static get tableName() { return 'pages' }
- static get jsonSchema () {
- return {
- type: 'object',
- required: ['path', 'title'],
- properties: {
- id: {type: 'integer'},
- path: {type: 'string'},
- title: {type: 'string'},
- description: {type: 'string'},
- isPublished: {type: 'boolean'},
- publishStartDate: {type: 'string'},
- publishEndDate: {type: 'string'},
- content: {type: 'string'},
- createdAt: {type: 'string'},
- updatedAt: {type: 'string'}
- }
- }
- }
- static get relationMappings() {
- return {
- tags: {
- relation: Model.ManyToManyRelation,
- modelClass: require('./tags'),
- join: {
- from: 'pages.id',
- through: {
- from: 'pageTags.pageId',
- to: 'pageTags.tagId'
- },
- to: 'tags.id'
- }
- },
- author: {
- relation: Model.BelongsToOneRelation,
- modelClass: require('./users'),
- join: {
- from: 'pages.authorId',
- to: 'users.id'
- }
- },
- locale: {
- relation: Model.BelongsToOneRelation,
- modelClass: require('./locales'),
- join: {
- from: 'users.locale',
- to: 'locales.code'
- }
- }
- }
- }
- $beforeUpdate() {
- this.updatedAt = new Date().toISOString()
- }
- $beforeInsert() {
- this.createdAt = new Date().toISOString()
- this.updatedAt = new Date().toISOString()
- }
- }
|