mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
import { Model } from 'objection';
|
|
import TenantModel from 'models/TenantModel';
|
|
import { AccountTransaction } from 'models';
|
|
|
|
export default class ManualJournal extends TenantModel {
|
|
/**
|
|
* Table name.
|
|
*/
|
|
static get tableName() {
|
|
return 'manual_journals';
|
|
}
|
|
|
|
/**
|
|
* Model timestamps.
|
|
*/
|
|
get timestamps() {
|
|
return ['createdAt', 'updatedAt'];
|
|
}
|
|
|
|
/**
|
|
* Relationship mapping.
|
|
*/
|
|
static get relationMappings() {
|
|
const Media = require('models/Media');
|
|
const AccountTransaction = require('models/AccountTransaction');
|
|
|
|
return {
|
|
entries: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: this.relationBindKnex(AccountTransaction.default),
|
|
join: {
|
|
from: 'manual_journals.id',
|
|
to: 'accounts_transactions.referenceId',
|
|
},
|
|
filter: (query) => {
|
|
query.where('referenceType', 'Journal');
|
|
},
|
|
},
|
|
media: {
|
|
relation: Model.ManyToManyRelation,
|
|
modelClass: this.relationBindKnex(Media.default),
|
|
join: {
|
|
from: 'manual_journals.id',
|
|
through: {
|
|
from: 'media_links.model_id',
|
|
to: 'media_links.media_id',
|
|
},
|
|
to: 'media.id',
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|