I’m using the following query:
$query = (new Query())
->from('customers')
->indexBy('name')
->all();
Shouldn’t this be returning the results sorted by ‘name’? Now the results is sorted by id (=the order they are in the db).
I’m using the following query:
$query = (new Query())
->from('customers')
->indexBy('name')
->all();
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
indexBy
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!