This commit is contained in:
cuiliang
2016-06-11 19:49:57 +08:00
2065 changed files with 88639 additions and 74804 deletions

View File

@@ -34,7 +34,7 @@ trait ActiveQueryTrait
/**
* Sets the [[asArray]] property.
* @param boolean $value whether to return the query results in terms of arrays instead of Active Records.
* @return static the query object itself
* @return $this the query object itself
*/
public function asArray($value = true)
{
@@ -53,35 +53,39 @@ trait ActiveQueryTrait
* For example, `orders.address` means the `address` relation defined
* in the model class corresponding to the `orders` relation.
*
<<<<<<< HEAD
<<<<<<< HEAD
* The followings are some usage examples:
=======
* The following are some usage examples:
>>>>>>> yiichina/master
=======
* The following are some usage examples:
>>>>>>> master
*
* ~~~
* ```php
* // find customers together with their orders and country
* Customer::find()->with('orders', 'country')->all();
* // find customers together with their orders and the orders' shipping address
* Customer::find()->with('orders.address')->all();
* // find customers together with their country and orders of status 1
* Customer::find()->with([
* 'orders' => function ($query) {
* 'orders' => function (\yii\db\ActiveQuery $query) {
* $query->andWhere('status = 1');
* },
* 'country',
* ])->all();
* ~~~
* ```
*
* You can call `with()` multiple times. Each call will add relations to the existing ones.
* For example, the following two statements are equivalent:
*
* ~~~
* ```php
* Customer::find()->with('orders', 'country')->all();
* Customer::find()->with('orders')->with('country')->all();
* ~~~
* ```
*
* @return static the query object itself
* @return $this the query object itself
*/
public function with()
{
@@ -95,7 +99,7 @@ trait ActiveQueryTrait
$this->with = $with;
} elseif (!empty($with)) {
foreach ($with as $name => $value) {
if (is_integer($name)) {
if (is_int($name)) {
// repeating relation is fine as normalizeRelations() handle it well
$this->with[] = $value;
} else {
@@ -163,7 +167,10 @@ trait ActiveQueryTrait
*/
public function findWith($with, &$models)
{
$primaryModel = new $this->modelClass;
$primaryModel = reset($models);
if (!$primaryModel instanceof ActiveRecordInterface) {
$primaryModel = new $this->modelClass;
}
$relations = $this->normalizeRelations($primaryModel, $with);
/* @var $relation ActiveQuery */
foreach ($relations as $name => $relation) {
@@ -184,7 +191,7 @@ trait ActiveQueryTrait
{
$relations = [];
foreach ($with as $name => $callback) {
if (is_integer($name)) {
if (is_int($name)) {
$name = $callback;
$callback = null;
}