Skip to content

Commit 5721e74

Browse files
committed
Fix eagerLoading
1 parent 269012d commit 5721e74

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

dist/vuex-orm-graphql.esm.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,17 +3767,22 @@ var Model = /** @class */ (function () {
37673767
* Determines if we should eager load (means: add as a field in the graphql query) a related entity. belongsTo or
37683768
* hasOne related entities are always eager loaded. Others can be added to the `eagerLoad` array of the model.
37693769
*
3770+
* @param {string} fieldName Name of the field
37703771
* @param {Field} field Relation field
37713772
* @param {Model} relatedModel Related model
37723773
* @returns {boolean}
37733774
*/
3774-
Model.prototype.shouldEagerLoadRelation = function (field, relatedModel) {
3775+
Model.prototype.shouldEagerLoadRelation = function (fieldName, field, relatedModel) {
37753776
var context = Context.getInstance();
3776-
if (field instanceof context.components.HasOne || field instanceof context.components.BelongsTo) {
3777+
if (field instanceof context.components.HasOne ||
3778+
field instanceof context.components.BelongsTo ||
3779+
field instanceof context.components.MorphOne) {
37773780
return true;
37783781
}
37793782
var eagerLoadList = this.baseModel.eagerLoad || [];
3780-
return eagerLoadList.find(function (n) { return n === relatedModel.singularName || n === relatedModel.pluralName; }) !== undefined;
3783+
return eagerLoadList.find(function (n) {
3784+
return n === relatedModel.singularName || n === relatedModel.pluralName || n === fieldName;
3785+
}) !== undefined;
37813786
};
37823787
return Model;
37833788
}());
@@ -10264,7 +10269,7 @@ var QueryBuilder = /** @class */ (function () {
1026410269
relatedModel = context.getModel(name);
1026510270
context.logger.log('WARNING: field has neither parent nor related property. Fallback to attribute name', field);
1026610271
}
10267-
if (model.shouldEagerLoadRelation(field, relatedModel) &&
10272+
if (model.shouldEagerLoadRelation(name, field, relatedModel) &&
1026810273
!_this.shouldRelationBeIgnored(model, relatedModel, ignoreRelations)) {
1026910274
var multiple = !(field instanceof context.components.BelongsTo ||
1027010275
field instanceof context.components.HasOne);

src/orm/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export default class Model {
202202
* Determines if we should eager load (means: add as a field in the graphql query) a related entity. belongsTo or
203203
* hasOne related entities are always eager loaded. Others can be added to the `eagerLoad` array of the model.
204204
*
205+
* @param {string} fieldName Name of the field
205206
* @param {Field} field Relation field
206207
* @param {Model} relatedModel Related model
207208
* @returns {boolean}

0 commit comments

Comments
 (0)