You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
const { Model } = require("objection");
|
|
|
|
module.exports = function ({ db }) {
|
|
return class Item extends Model {
|
|
static tableName = "items";
|
|
|
|
static get relationMappings() {
|
|
return {
|
|
aliases: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: db.Alias,
|
|
join: { from: "items.id", to: "aliases.itemId" }
|
|
},
|
|
tags: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: db.Tag,
|
|
join: { from: "items.id", to: "tags.itemId" }
|
|
},
|
|
taskResults: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: db.TaskResult,
|
|
join: { from: "items.id", to: "taskResults.itemId" }
|
|
},
|
|
tasksInProgress: {
|
|
relation: Model.HasManyRelation,
|
|
modelClass: db.TaskInProgress,
|
|
join: { from: "items.id", to: "tasksInProgress.itemId" }
|
|
},
|
|
failedTasks: {
|
|
// Not actually a many-to-many, but that's what objection calls a HasManyThrough...
|
|
// https://github.com/Vincit/objection.js/issues/1148
|
|
relation: Model.ManyToManyRelation,
|
|
modelClass: db.Failure,
|
|
join: {
|
|
from: "items.id",
|
|
through: { from: "task_results.itemId", to: "task_results.id" },
|
|
to: "failures.taskResultId"
|
|
}
|
|
}
|
|
};
|
|
};
|
|
}
|
|
};
|