Finished refactoring find() .

This commit is contained in:
Qiang Xue
2014-04-07 16:29:12 -04:00
parent b7d6f6141a
commit 0e143338d7
10 changed files with 148 additions and 62 deletions

View File

@ -169,10 +169,9 @@ $customers = Customer::findBySql($sql)->all();
use meaningful constant names rather than hardcoded strings or numbers in your code.
There is a shortcut method `findOne()` that allows you to retrieve an Active Record instance based on a primary
key value or a set of column values. The main difference here is that instead of returning a [[yii\db\ActiveQuery]]
instance, the method takes the column value(s) and returns an Active Record instance directly without the need
to call `one()`.
Two shortcut methods are provided to return Active Record instances matching a primary key value or a set of
column values: `findOne()` and `findAll()`. The former returns the first matching instance while the latter
returns all of them. For example,
```php
// to return a single customer whose ID is 1:
@ -183,6 +182,14 @@ $customer = Customer::findOne([
'id' => 1,
'status' => Customer::STATUS_ACTIVE,
]);
// to return customers whose ID is 1, 2 or 3:
$customers = Customer::findAll([1, 2, 3]);
// to return customers whose status is "deleted":
$customer = Customer::findAll([
'status' => Customer::STATUS_DELETED,
]);
```