123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- const Model = require('objection').Model
- /**
- * Settings model
- */
- module.exports = class Group extends Model {
- static get tableName() { return 'groups' }
- static get jsonSchema () {
- return {
- type: 'object',
- required: ['name'],
- properties: {
- id: {type: 'integer'},
- name: {type: 'string'},
- createdAt: {type: 'string'},
- updatedAt: {type: 'string'}
- }
- }
- }
- static get relationMappings() {
- const User = require('./users')
- return {
- users: {
- relation: Model.ManyToManyRelation,
- modelClass: User,
- join: {
- from: 'groups.id',
- through: {
- from: 'userGroups.groupId',
- to: 'userGroups.userId'
- },
- to: 'users.id'
- }
- }
- }
- }
- $beforeUpdate() {
- this.updatedAt = new Date().toISOString()
- }
- $beforeInsert() {
- this.createdAt = new Date().toISOString()
- this.updatedAt = new Date().toISOString()
- }
- }
|