@@ -3767,17 +3767,22 @@ var Model = /** @class */ (function () {
3767
3767
* Determines if we should eager load (means: add as a field in the graphql query) a related entity. belongsTo or
3768
3768
* hasOne related entities are always eager loaded. Others can be added to the `eagerLoad` array of the model.
3769
3769
*
3770
+ * @param {string } fieldName Name of the field
3770
3771
* @param {Field } field Relation field
3771
3772
* @param {Model } relatedModel Related model
3772
3773
* @returns {boolean }
3773
3774
*/
3774
- Model . prototype . shouldEagerLoadRelation = function ( field , relatedModel ) {
3775
+ Model . prototype . shouldEagerLoadRelation = function ( fieldName , field , relatedModel ) {
3775
3776
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 ) {
3777
3780
return true ;
3778
3781
}
3779
3782
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 ;
3781
3786
} ;
3782
3787
return Model ;
3783
3788
} ( ) ) ;
@@ -10264,7 +10269,7 @@ var QueryBuilder = /** @class */ (function () {
10264
10269
relatedModel = context . getModel ( name ) ;
10265
10270
context . logger . log ( 'WARNING: field has neither parent nor related property. Fallback to attribute name' , field ) ;
10266
10271
}
10267
- if ( model . shouldEagerLoadRelation ( field , relatedModel ) &&
10272
+ if ( model . shouldEagerLoadRelation ( name , field , relatedModel ) &&
10268
10273
! _this . shouldRelationBeIgnored ( model , relatedModel , ignoreRelations ) ) {
10269
10274
var multiple = ! ( field instanceof context . components . BelongsTo ||
10270
10275
field instanceof context . components . HasOne ) ;
0 commit comments