123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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'
- }
- },
- editor: {
- relation: Model.BelongsToOneRelation,
- modelClass: require('./editors'),
- join: {
- from: 'pages.editorKey',
- to: 'editors.key'
- }
- },
- locale: {
- relation: Model.BelongsToOneRelation,
- modelClass: require('./locales'),
- join: {
- from: 'pages.localeCode',
- to: 'locales.code'
- }
- }
- }
- }
- $beforeUpdate() {
- this.updatedAt = new Date().toISOString()
- }
- $beforeInsert() {
- this.createdAt = new Date().toISOString()
- this.updatedAt = new Date().toISOString()
- }
- }
|