-
Notifications
You must be signed in to change notification settings - Fork 643
Closed
Labels
Description
I believe this is related to issue #1206 , but I wanted to provide additional details just in case it would help.
I can execute the queries in 1.4.0 using both join and joinRelation, and in 1.5.0 and above I can only use join. It fails on joinRelation.
// This one fails and the sql is missing the relation and the error returns that it can't find the table item
const failedResults = await Model
.query()
.eager('joinRelationItems')
.findById(6468);
// functionally the same as the first just uses a join in the filter
const workingResults = await Model
.query()
.eager('joinItems')
.findById(6468);
The following model definitions were used on a MySQL backend using pretty simple table structures
const Model = require('objection').Model;
class TemplateSection extends Model {
static get tableName() {
return "template_sections";
}
static get relationMappings() {
return {
joinRelationItems: {
relation: Model.HasManyRelation,
modelClass: TemplateSectionItem,
join: {
from: "template_sections.id",
to: "template_section_items.template_section_id"
},
filter: query => query
.select(
'template_section_items.id as template_section_item_id',
'item.*')
.joinRelation('item')
},
joinItems: {
relation: Model.HasManyRelation,
modelClass: TemplateSectionItem,
join: {
from: "template_sections.id",
to: "template_section_items.template_section_id"
},
filter: query => query
.select(
'template_section_items.id as template_section_item_id',
'item.*')
.join('template_items as item','template_section_items.template_item_id', 'item.id')
}
};
}
}
class TemplateSectionItem extends Model {
static get tableName() {
return "template_section_items";
}
static get relationMappings() {
return {
item: {
relation: Model.HasOneRelation,
modelClass: TemplateItem,
join: {
from: "template_section_items.template_item_id",
to: "template_items.id"
},
}
};
}
}
class TemplateItem extends Model {
static get tableName() {
return 'template_items';
}
}