@@ -7980,8 +7980,8 @@ var QueryBuilder = /** @class */ (function () {
79807980 /**
79817981 *
79827982 * @param {Model } model
7983- * @param {Array<Model> } ignoreModels The models in this list are ignored (while traversing relations). Mainly for recursion
7984- * @returns {Array<String> }
7983+ * @param {Array<Model> } ignoreModels The models in this list are ignored (while traversing relations).
7984+ * @returns {string }
79857985 */
79867986 QueryBuilder . prototype . buildRelationsQuery = function ( model , ignoreModels ) {
79877987 var _this = this ;
@@ -7990,12 +7990,29 @@ var QueryBuilder = /** @class */ (function () {
79907990 return '' ;
79917991 var relationQueries = [ ] ;
79927992 model . getRelations ( ) . forEach ( function ( field , name ) {
7993- if ( ! _this . shouldModelBeIgnored ( _this . getModel ( name ) , ignoreModels ) ) {
7993+ var relatedModel = _this . getModel ( name ) ;
7994+ if ( _this . shouldEagerLoadRelation ( model , field , relatedModel ) &&
7995+ ! _this . shouldModelBeIgnored ( relatedModel , ignoreModels ) ) {
79947996 var multiple = field . constructor . name !== 'BelongsTo' ;
7995- relationQueries . push ( _this . buildField ( name , multiple , undefined , ignoreModels ) ) ;
7997+ relationQueries . push ( _this . buildField ( relatedModel , multiple , undefined , ignoreModels ) ) ;
79967998 }
79977999 } ) ;
7998- return relationQueries ;
8000+ return relationQueries . join ( '\n' ) ;
8001+ } ;
8002+ /**
8003+ * Determines if we should eager load (means: add a query field) a related entity. belongsTo related entities
8004+ * are always eager loaded. Others can be added to the eagerLoad array of the model.
8005+ *
8006+ * @param {Model } model The base model
8007+ * @param {Field } field Relation field
8008+ * @param {Model } relatedModel Related model
8009+ * @returns {boolean }
8010+ */
8011+ QueryBuilder . prototype . shouldEagerLoadRelation = function ( model , field , relatedModel ) {
8012+ if ( field . constructor . name === 'BelongsTo' )
8013+ return true ;
8014+ var eagerLoadList = model . baseModel . eagerLoad || [ ] ;
8015+ return eagerLoadList . find ( function ( n ) { return n === relatedModel . singularName || n === relatedModel . pluralName ; } ) !== undefined ;
79998016 } ;
80008017 QueryBuilder . prototype . shouldModelBeIgnored = function ( model , ignoreModels ) {
80018018 return ignoreModels . find ( function ( m ) { return m . singularName === model . singularName ; } ) !== undefined ;
@@ -8236,7 +8253,7 @@ var VuexORMApollo = /** @class */ (function () {
82368253 name = args [ 'mutation' ] ;
82378254 delete args [ 'mutation' ] ;
82388255 model = this . getModel ( state . $name ) ;
8239- return [ 2 /*return*/ , this . mutate ( name , args , dispatch , model ) ] ;
8256+ return [ 2 /*return*/ , this . mutate ( name , args , dispatch , model , false ) ] ;
82408257 } ) ;
82418258 } ) ;
82428259 } ;
0 commit comments