redirection_host.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Objection Docs:
  2. // http://vincit.github.io/objection.js/
  3. 'use strict';
  4. const db = require('../db');
  5. const Model = require('objection').Model;
  6. const User = require('./user');
  7. Model.knex(db);
  8. class RedirectionHost extends Model {
  9. $beforeInsert () {
  10. this.created_on = Model.raw('NOW()');
  11. this.modified_on = Model.raw('NOW()');
  12. }
  13. $beforeUpdate () {
  14. this.modified_on = Model.raw('NOW()');
  15. }
  16. static get name () {
  17. return 'RedirectionHost';
  18. }
  19. static get tableName () {
  20. return 'redirection_host';
  21. }
  22. static get relationMappings () {
  23. return {
  24. owner: {
  25. relation: Model.HasOneRelation,
  26. modelClass: User,
  27. join: {
  28. from: 'redirection_host.owner_user_id',
  29. to: 'user.id'
  30. },
  31. modify: function (qb) {
  32. qb.where('user.is_deleted', 0);
  33. qb.omit(['created_on', 'modified_on', 'is_deleted', 'email', 'roles']);
  34. }
  35. }
  36. };
  37. }
  38. }
  39. module.exports = RedirectionHost;