indexBy does not work

I’m using the following query:

$query = (new Query())




Shouldn’t this be returning the results sorted by ‘name’? Now the results is sorted by id (=the order they are in the db).

Use "orderBy" method.

To complete @hableel answer


Normally you get a result set which is an array of ActiveRecord.

The array index is from 0 to N

If you use indexBy, the array index is the value in filed specified.

Ok, thanks!