cleanup docs and duplicate code in query

This commit is contained in:
Carsten Brandt
2015-11-25 13:36:12 +01:00
parent 31cf978f38
commit 7c7ed48c4c
2 changed files with 21 additions and 31 deletions

View File

@ -39,6 +39,7 @@ use yii\base\InvalidConfigException;
* ActiveQuery also provides the following additional query options: * ActiveQuery also provides the following additional query options:
* *
* - [[with()]]: list of relations that this query should be performed with. * - [[with()]]: list of relations that this query should be performed with.
* - [[joinWith()]]: reuse a relation query definition to add a join to a query.
* - [[indexBy()]]: the name of the column by which the query result should be indexed. * - [[indexBy()]]: the name of the column by which the query result should be indexed.
* - [[asArray()]]: whether to return each record as an array. * - [[asArray()]]: whether to return each record as an array.
* *
@ -154,19 +155,8 @@ class ActiveQuery extends Query implements ActiveQueryInterface
} }
if (empty($this->select) && !empty($this->join)) { if (empty($this->select) && !empty($this->join)) {
foreach ((array) $this->from as $alias => $table) { list(, $alias) = $this->getQueryTableName($this);
if (is_string($alias)) { $this->select = ["$alias.*"];
$this->select = ["$alias.*"];
} elseif (is_string($table)) {
if (preg_match('/^(.*?)\s+({{\w+}}|\w+)$/', $table, $matches)) {
$alias = $matches[2];
} else {
$alias = $table;
}
$this->select = ["$alias.*"];
}
break;
}
} }
if ($this->primaryModel === null) { if ($this->primaryModel === null) {
@ -442,8 +432,8 @@ class ActiveQuery extends Query implements ActiveQueryInterface
* Inner joins with the specified relations. * Inner joins with the specified relations.
* This is a shortcut method to [[joinWith()]] with the join type set as "INNER JOIN". * This is a shortcut method to [[joinWith()]] with the join type set as "INNER JOIN".
* Please refer to [[joinWith()]] for detailed usage of this method. * Please refer to [[joinWith()]] for detailed usage of this method.
* @param string|array $with the relations to be joined with * @param string|array $with the relations to be joined with.
* @param boolean|array $eagerLoading whether to eager loading the relations * @param boolean|array $eagerLoading whether to eager loading the relations.
* @return $this the query object itself * @return $this the query object itself
* @see joinWith() * @see joinWith()
*/ */

View File

@ -583,13 +583,13 @@ class Query extends Component implements QueryInterface
* @param string $type the type of join, such as INNER JOIN, LEFT JOIN. * @param string $type the type of join, such as INNER JOIN, LEFT JOIN.
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of the table to be joined. * Use a string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis * The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression). * (which means the table is given as a sub-query or DB expression).
* *
* Use array to represent joining with a sub-query. The array must contain only one element. * Use an array to represent joining with a sub-query. The array must contain only one element.
* The value must be a Query object representing the sub-query while the corresponding key * The value must be a [[Query]] object representing the sub-query while the corresponding key
* represents the alias for the sub-query. * represents the alias for the sub-query.
* *
* @param string|array $on the join condition that should appear in the ON part. * @param string|array $on the join condition that should appear in the ON part.
@ -607,13 +607,13 @@ class Query extends Component implements QueryInterface
* Appends an INNER JOIN part to the query. * Appends an INNER JOIN part to the query.
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of the table to be joined. * Use a string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis * The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression). * (which means the table is given as a sub-query or DB expression).
* *
* Use array to represent joining with a sub-query. The array must contain only one element. * Use an array to represent joining with a sub-query. The array must contain only one element.
* The value must be a Query object representing the sub-query while the corresponding key * The value must be a [[Query]] object representing the sub-query while the corresponding key
* represents the alias for the sub-query. * represents the alias for the sub-query.
* *
* @param string|array $on the join condition that should appear in the ON part. * @param string|array $on the join condition that should appear in the ON part.
@ -631,13 +631,13 @@ class Query extends Component implements QueryInterface
* Appends a LEFT OUTER JOIN part to the query. * Appends a LEFT OUTER JOIN part to the query.
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of the table to be joined. * Use a string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis * The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression). * (which means the table is given as a sub-query or DB expression).
* *
* Use array to represent joining with a sub-query. The array must contain only one element. * Use an array to represent joining with a sub-query. The array must contain only one element.
* The value must be a Query object representing the sub-query while the corresponding key * The value must be a [[Query]] object representing the sub-query while the corresponding key
* represents the alias for the sub-query. * represents the alias for the sub-query.
* *
* @param string|array $on the join condition that should appear in the ON part. * @param string|array $on the join condition that should appear in the ON part.
@ -655,13 +655,13 @@ class Query extends Component implements QueryInterface
* Appends a RIGHT OUTER JOIN part to the query. * Appends a RIGHT OUTER JOIN part to the query.
* @param string|array $table the table to be joined. * @param string|array $table the table to be joined.
* *
* Use string to represent the name of the table to be joined. * Use a string to represent the name of the table to be joined.
* Table name can contain schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u').
* The method will automatically quote the table name unless it contains some parenthesis * The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression). * (which means the table is given as a sub-query or DB expression).
* *
* Use array to represent joining with a sub-query. The array must contain only one element. * Use an array to represent joining with a sub-query. The array must contain only one element.
* The value must be a Query object representing the sub-query while the corresponding key * The value must be a [[Query]] object representing the sub-query while the corresponding key
* represents the alias for the sub-query. * represents the alias for the sub-query.
* *
* @param string|array $on the join condition that should appear in the ON part. * @param string|array $on the join condition that should appear in the ON part.