2023-03-03 15:54:28 +00:00
|
|
|
import {
|
2023-06-22 15:20:04 +00:00
|
|
|
column,
|
|
|
|
BaseModel,
|
|
|
|
SnakeCaseNamingStrategy,
|
|
|
|
manyToMany,
|
|
|
|
ManyToMany,
|
|
|
|
belongsTo,
|
|
|
|
BelongsTo,
|
|
|
|
hasMany,
|
|
|
|
HasMany,
|
2023-03-03 15:54:28 +00:00
|
|
|
} from '@ioc:Adonis/Lucid/Orm';
|
|
|
|
import { DateTime } from 'luxon';
|
|
|
|
import Person from './Person';
|
2023-06-22 15:20:04 +00:00
|
|
|
import User from './User';
|
|
|
|
import Title from './Title';
|
|
|
|
import Description from './Description';
|
|
|
|
import License from './License';
|
|
|
|
import Subject from './Subject';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
export default class Dataset extends BaseModel {
|
2023-06-22 15:20:04 +00:00
|
|
|
public static namingStrategy = new SnakeCaseNamingStrategy();
|
|
|
|
public static primaryKey = 'id';
|
|
|
|
public static table = 'documents';
|
|
|
|
public static selfAssignPrimaryKey = false;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({ isPrimary: true })
|
|
|
|
public id: number;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column({})
|
2023-06-22 15:20:04 +00:00
|
|
|
public server_state: boolean;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column({})
|
2023-06-22 15:20:04 +00:00
|
|
|
public publisherName: string;
|
|
|
|
|
|
|
|
@column({ columnName: 'creating_corporation' })
|
|
|
|
public creatingCorporation: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column.dateTime({ columnName: 'embargo_date' })
|
2023-06-22 15:20:04 +00:00
|
|
|
public embargoDate: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@column({})
|
2023-06-22 15:20:04 +00:00
|
|
|
public type: string;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column({})
|
|
|
|
public language: string;
|
|
|
|
|
|
|
|
@column({})
|
|
|
|
public account_id: number | null = null;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column.dateTime({ columnName: 'server_date_published' })
|
|
|
|
public serverDatePublished: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column.dateTime({ autoCreate: true, columnName: 'created_at' })
|
|
|
|
public createdAt: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true, columnName: 'server_date_modified' })
|
|
|
|
public updatedAt: DateTime;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
@manyToMany(() => Person, {
|
2023-06-22 15:20:04 +00:00
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'person_id',
|
|
|
|
pivotTable: 'link_documents_persons',
|
|
|
|
pivotColumns: ['role', 'sort_order', 'allow_email_contact'],
|
|
|
|
})
|
|
|
|
public persons: ManyToMany<typeof Person>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the account that the dataset belongs to
|
|
|
|
*/
|
|
|
|
@belongsTo(() => User, {
|
|
|
|
foreignKey: 'account_id',
|
|
|
|
})
|
|
|
|
public user: BelongsTo<typeof User>;
|
|
|
|
|
|
|
|
@hasMany(() => Title, {
|
|
|
|
foreignKey: 'document_id',
|
|
|
|
})
|
|
|
|
public titles: HasMany<typeof Title>;
|
|
|
|
|
|
|
|
@hasMany(() => Description, {
|
|
|
|
foreignKey: 'document_id',
|
|
|
|
})
|
|
|
|
public descriptions: HasMany<typeof Description>;
|
|
|
|
|
|
|
|
@manyToMany(() => License, {
|
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'licence_id',
|
|
|
|
pivotTable: 'link_documents_licences',
|
|
|
|
})
|
|
|
|
public licenses: ManyToMany<typeof License>;
|
|
|
|
|
|
|
|
// public function subjects()
|
|
|
|
// {
|
|
|
|
// return $this->belongsToMany(\App\Models\Subject::class, 'link_dataset_subjects', 'document_id', 'subject_id');
|
|
|
|
// }
|
|
|
|
@manyToMany(() => Subject, {
|
|
|
|
pivotForeignKey: 'document_id',
|
|
|
|
pivotRelatedForeignKey: 'subject_id',
|
|
|
|
pivotTable: 'link_dataset_subjects',
|
|
|
|
})
|
|
|
|
public subjects: ManyToMany<typeof Subject>;
|
2023-03-03 15:54:28 +00:00
|
|
|
|
2023-06-22 15:20:04 +00:00
|
|
|
// async save(): Promise<this> {
|
|
|
|
// // Call the parent save method to persist changes to the database
|
|
|
|
// await super.save();
|
|
|
|
// return this;
|
|
|
|
// }
|
2023-03-03 15:54:28 +00:00
|
|
|
}
|