common/models/base/ActiveRecord.php
public static function queryWithAll( $config = [] ) {

		// Query Config --------

		$query			= static::find();

		$relations		= isset( $config[ 'relations' ] ) ? $config[ 'relations' ] : [];
		$conditions		= isset( $config[ 'conditions' ] ) ? $config[ 'conditions' ] : null;
		$filters		= isset( $config[ 'filters' ] ) ? $config[ 'filters' ] : null;
		$groups			= isset( $config[ 'groups' ] ) ? $config[ 'groups' ] : null;

		// Relations -----------

		$eager	= false;
		$join	= 'LEFT JOIN';

		foreach ( $relations as $relation ) {

			if( is_array( $relation ) && isset( $relation[ 'relation' ] ) ) {

				$eager	= isset( $relation[ 'eager' ] ) ? $relation[ 'eager' ] : false;
				$join	= isset( $relation[ 'join' ] ) ? $relation[ 'join' ] : 'LEFT JOIN';

				$query->joinWith( $relation[ 'relation' ], $eager, $join );
			}
			else {

				$query->joinWith( $relation );
			}
		}

		// Conditions ----------

		if( isset( $conditions ) ) {

			foreach ( $conditions as $ckey => $condition ) {

				if( is_numeric( $ckey ) ) {

					$query->andWhere( $condition );

					unset( $conditions[ $ckey ] );
				}
			}

			$query->andWhere( $conditions );
		}

		// Filters -------------

		if( isset( $filters ) ) {

			foreach ( $filters as $filter ) {

				$query = $query->andFilterWhere( $filter );
			}
		}

		// Grouping -------------

		if( isset( $groups ) ) {

			foreach ( $groups as $group ) {

				$query	= $query->groupBy( $group );
			}
		}

		$ignoreSite	= isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;

		if( static::isMultiSite() && !$ignoreSite ) {

			$siteId	= isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;

			$modelTable = static::tableName();

			$query = $query->andWhere( "$modelTable.siteId=:siteId", [ ':siteId' => $siteId ] );
		}

		return $query;
	}
public static function queryWithAll( $config = [] ) {

		// Query Config --------

		$query			= static::find();

		$relations		= isset( $config[ 'relations' ] ) ? $config[ 'relations' ] : [];
		$conditions		= isset( $config[ 'conditions' ] ) ? $config[ 'conditions' ] : null;
		$filters		= isset( $config[ 'filters' ] ) ? $config[ 'filters' ] : null;
		$groups			= isset( $config[ 'groups' ] ) ? $config[ 'groups' ] : null;

		// Relations -----------

		$eager	= false;
		$join	= 'LEFT JOIN';

		foreach ( $relations as $relation ) {

			if( is_array( $relation ) && isset( $relation[ 'relation' ] ) ) {

				$eager	= isset( $relation[ 'eager' ] ) ? $relation[ 'eager' ] : false;
				$join	= isset( $relation[ 'join' ] ) ? $relation[ 'join' ] : 'LEFT JOIN';

				$query->joinWith( $relation[ 'relation' ], $eager, $join );
			}
			else {

				$query->joinWith( $relation );
			}
		}

		// Conditions ----------

		if( isset( $conditions ) ) {

			foreach ( $conditions as $ckey => $condition ) {

				if( is_numeric( $ckey ) ) {

					$query->andWhere( $condition );

					unset( $conditions[ $ckey ] );
				}
			}

			$query->andWhere( $conditions );
		}

		// Filters -------------

		if( isset( $filters ) ) {

			foreach ( $filters as $filter ) {

				$query = $query->andFilterWhere( $filter );
			}
		}

		// Grouping -------------

		if( isset( $groups ) ) {

			foreach ( $groups as $group ) {

				$query	= $query->groupBy( $group );
			}
		}

		$ignoreSite	= isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;

		if( static::isMultiSite() && !$ignoreSite ) {

			$siteId	= isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;

			$modelTable = static::tableName();

			$query = $query->andWhere( "$modelTable.siteId=:siteId", [ ':siteId' => $siteId ] );
		}

		return $query;
	}
public static function queryWithAll ( $ config = [ ] ) { // Query Config -------- $ query = static :: find ( ) ; $ relations = isset ( $ config [ 'relations' ] ) ? $ config [ 'relations' ] : [ ] ; $ conditions = isset ( $ config [ 'conditions' ] ) ? $ config [ 'conditions' ] : null ; $ filters = isset ( $ config [ 'filters' ] ) ? $ config [ 'filters' ] : null ; $ groups = isset ( $ config [ 'groups' ] ) ? $ config [ 'groups' ] : null ; // Relations ----------- $ eager = false ; $ join = 'LEFT JOIN' ; foreach ( $ relations as $ relation ) { if ( is_array ( $ relation ) && isset ( $ relation [ 'relation' ] ) ) { $ eager = isset ( $ relation [ 'eager' ] ) ? $ relation [ 'eager' ] : false ; $ join = isset ( $ relation [ 'join' ] ) ? $ relation [ 'join' ] : 'LEFT JOIN' ; $ query -> joinWith ( $ relation [ 'relation' ] , $ eager , $ join ) ; } else { $ query -> joinWith ( $ relation ) ; } } // Conditions ---------- if ( isset ( $ conditions ) ) { foreach ( $ conditions as $ ckey => $ condition ) { if ( is_numeric ( $ ckey ) ) { $ query -> andWhere ( $ condition ) ; unset ( $ conditions [ $ ckey ] ) ; } } $ query -> andWhere ( $ conditions ) ; } // Filters ------------- if ( isset ( $ filters ) ) { foreach ( $ filters as $ filter ) { $ query = $ query -> andFilterWhere ( $ filter ) ; } } // Grouping ------------- if ( isset ( $ groups ) ) { foreach ( $ groups as $ group ) { $ query = $ query -> groupBy ( $ group ) ; } } $ ignoreSite = isset ( $ config [ 'ignoreSite' ] ) ? $ config [ 'ignoreSite' ] : false ; if ( static :: isMultiSite ( ) && ! $ ignoreSite ) { $ siteId = isset ( $ config [ 'siteId' ] ) ? $ config [ 'siteId' ] : Yii :: $ app -> core -> siteId ; $ modelTable = static :: tableName ( ) ; $ query = $ query -> andWhere ( "$modelTable.siteId=:siteId" , [ ':siteId' => $ siteId ] ) ; } return $ query ; }
Generates and return query with model relations.

* Relations - The relations are method name without get prefix of methods returning
query generated by one-to-one(hasOne) or one-to-many(hasMany) called within the method.
* Conditions - Conditions to be applied to further filter the results of query generated
after applying all the relations.
* Filters - Filters applied on top of conditions to further filter the results.
* Groups - Group By Column applied on the query generate after applying all the
relations, conditions and filters.

The final query generated by this method will be returned to generate results.

@param array $config query configurations.
@return \yii\db\ActiveQuery to query with related models.
Generates and return query with model relations .