Skip to content

Commit b30c383

Browse files
committed
Bugifx: Use correct model name for belongsTo relations
1 parent 0be67c0 commit b30c383

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7939,7 +7939,17 @@ var QueryBuilder = /** @class */ (function () {
79397939
return '';
79407940
var relationQueries = [];
79417941
model.getRelations().forEach(function (field, name) {
7942-
var relatedModel = _this.getModel(field.related ? field.related.name : name);
7942+
var relatedModel;
7943+
if (field.related) {
7944+
relatedModel = _this.getModel(field.related.name);
7945+
}
7946+
else if (field.parent) {
7947+
relatedModel = _this.getModel(field.parent.name);
7948+
}
7949+
else {
7950+
relatedModel = _this.getModel(name);
7951+
_this.context.logger.log('WARNING: field has neither parent nor related property. Fallback to attribute name', field);
7952+
}
79437953
if (_this.shouldEagerLoadRelation(model, field, relatedModel) &&
79447954
!_this.shouldModelBeIgnored(relatedModel, ignoreModels)) {
79457955
var multiple = !(field instanceof _this.context.components.BelongsTo ||

src/queryBuilder.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,17 @@ export default class QueryBuilder {
270270
const relationQueries: Array<string> = [];
271271

272272
model.getRelations().forEach((field: Field, name: string) => {
273-
const relatedModel: Model = this.getModel(field.related ? field.related.name : name);
273+
let relatedModel: Model;
274+
275+
if (field.related) {
276+
relatedModel = this.getModel(field.related.name);
277+
} else if (field.parent) {
278+
relatedModel = this.getModel(field.parent.name);
279+
} else {
280+
relatedModel = this.getModel(name);
281+
this.context.logger.log('WARNING: field has neither parent nor related property. Fallback to attribute name',
282+
field);
283+
}
274284

275285
if (this.shouldEagerLoadRelation(model, field, relatedModel) &&
276286
!this.shouldModelBeIgnored(relatedModel, ignoreModels)) {

0 commit comments

Comments
 (0)