yiisoft / yiisoft/db

Add `ArrangeBy` option

Open
#923 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:enhancement
Dominant language
PHP
Stars
216
Forks
51
Avg merge
3d 10h
Merged PRs (30d)
2

Description

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,        
    ],
];

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the ActiveQuery entry point and its existing IndexBy behavior. Compare the requested ArrangeBy example with that behavior, then determine the project’s relevant query tests before implementing the grouping result. Done means arrangeBy('status')->all() returns records grouped by status as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.