@@ -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 ) ;
0 commit comments