mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Added support for using callables as "ActiveQuery::indexBy".
This commit is contained in:
@ -84,6 +84,15 @@ class ActiveRecordTest extends DatabaseTestCase
|
||||
$this->assertTrue($customers['user1'] instanceof Customer);
|
||||
$this->assertTrue($customers['user2'] instanceof Customer);
|
||||
$this->assertTrue($customers['user3'] instanceof Customer);
|
||||
|
||||
// indexBy callable
|
||||
$customers = Customer::find()->indexBy(function($customer) {
|
||||
return $customer->id . '-' . $customer->name;
|
||||
})->orderBy('id')->all();
|
||||
$this->assertEquals(3, count($customers));
|
||||
$this->assertTrue($customers['1-user1'] instanceof Customer);
|
||||
$this->assertTrue($customers['2-user2'] instanceof Customer);
|
||||
$this->assertTrue($customers['3-user3'] instanceof Customer);
|
||||
}
|
||||
|
||||
public function testFindBySql()
|
||||
|
||||
Reference in New Issue
Block a user