Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Model } = require('objection');
- class Client extends Model {
- static get tableName() {
- return 'Client';
- }
- static get idColumn() {
- return 'id';
- }
- static get jsonSchema() {
- return {
- type: "object",
- properties: {
- id: { type: "string", format: "uuid" },
- company_nif: { type: ['integer', 'null'] }
- }
- }
- }
- static get relationMappings() {
- const Company = require('./Company');
- const Subscription = require('./Subscription');
- return {
- company: {
- relation: Model.BelongsToOneRelation,
- modelClass: Company,
- join: {
- from: 'Client.company_nif',
- to: 'Company.company_nif'
- }
- },
- subscriptions: {
- relation: Model.HasManyRelation,
- modelClass: Subscription,
- join: {
- from: 'Client.id',
- to: 'Subscription.client_id'
- }
- },
- }
- }
- $beforeInsert() {
- this.created_at = new Date().toISOString();
- }
- $beforeUpdate() {
- this.updated_at = new Date().toISOString();
- }
- };
- module.exports = Client;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement