- small adaptions for back referencing internal datasets

This commit is contained in:
Arno Kaimbacher 2023-07-06 12:56:43 +02:00
parent 221dff8208
commit f3fe300a66
3 changed files with 38 additions and 1 deletions

View File

@ -61,7 +61,20 @@ export class DatasetController {
"coverage", "coverage",
"licenses", "licenses",
"references", "references",
// "referenced_by",
"project", "project",
{
model: dbContext.Reference,
as: "referenced_by",
include: [
{
model: dbContext.Dataset,
as: "dataset",
foreignKey: "document_id",
include: ["identifier"],
},
],
},
// "files", // "files",
{ {
model: dbContext.File, model: dbContext.File,
@ -149,7 +162,20 @@ export class DatasetController {
"coverage", "coverage",
"licenses", "licenses",
"references", "references",
// "referenced_by",
"project", "project",
{
model: dbContext.Reference,
as: "referenced_by",
include: [
{
model: dbContext.Dataset,
as: "dataset",
foreignKey: "document_id",
include: ["identifier"],
},
],
},
// "files", // "files",
{ {
model: dbContext.File, model: dbContext.File,

View File

@ -24,6 +24,7 @@ class Reference extends Model<InferAttributes<Reference>, InferCreationAttribute
declare created_at: CreationOptional<Date>; declare created_at: CreationOptional<Date>;
// updatedAt can be undefined during creation // updatedAt can be undefined during creation
declare updated_at: CreationOptional<Date>; declare updated_at: CreationOptional<Date>;
declare related_document_id?: number;
// https://sequelize.org/docs/v6/other-topics/typescript/ // https://sequelize.org/docs/v6/other-topics/typescript/
// Since TS cannot determine model association at compile time // Since TS cannot determine model association at compile time

View File

@ -210,6 +210,15 @@ export function initModels() {
foreignKey: "document_id", foreignKey: "document_id",
as: "dataset", as: "dataset",
}); });
Dataset.hasMany(Reference, {
foreignKey: "related_document_id",
as: "referenced_by",
});
Reference.belongsTo(Dataset, {
foreignKey: "related_document_id",
as: "new_dataset",
include: "identifier"
});
//project relations //project relations
Project.hasMany(Dataset, { Project.hasMany(Dataset, {
@ -279,6 +288,7 @@ export function initModels() {
Subject: Subject, Subject: Subject,
License: License, License: License,
DocumentPersons: DocumentPersons, DocumentPersons: DocumentPersons,
File: File File: File,
Reference: Reference
}; };
} }