yiisoft / active-record

Active Record database abstraction layer
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
68 stars 28 forks source link

Add `ArrangeBy` option #360

Open Tigrov opened 3 months ago

Tigrov commented 3 months ago

Similar to IndexBy, this option will arrange records by a value.

For example

$userQuery = new ActiveQuery(User::class, $db);

$users = $userQuery->arrangeBy('status')->all();

The result is

[
    'active' => [
        0 => User,
        1 => User,
        2 => User,
    ],
    'inactive' => [
        0 => User,
        1 => User,        
    ],
];
vjik commented 3 months ago

It's also will be userfull in Query from Yii DB.