Passing multiple custom expressions or parameters of different type to orderBy causes error
Closed this issue · 1 comments
samiharju commented
- If you pass more than one instances of
Expression
as parameters fororderBy()
- If you are using multiple parameters for
orderBy()
and one of them isExpression
The following error occurs:
Illegal offset
type on /clancats/hydrahon/src/Query/Sql/Select.php
at line 284.
mario-deluna commented
The easiest way around this bug is going to be to simply chain the orderBy
statements.
$h->table('people')->select()
->orderBy(new Expression('func1()'))
->orderBy(new Expression('func2()'), 'desc')
->execute();
select * from `people` order by func1() asc, func2() desc
There is still a problem with the internal data structure of the order statements but I will release a Fix soon at least allowing expressions in the order array.
$h->table('people')->select()
->orderBy([new Expression('rand()'), new Expression('rand()')])
->execute();
select * from `people` order by func1() asc, func2() asc
There is currently no way changing the direction per order statement in the array syntax. So the direction is set for all given order statements in the array.
$h->table('people')->select()
->orderBy([new Expression('func1()'), new Expression('func2()')], 'desc')
->execute();
select * from `people` order by func1() desc, func2() desc
The fix should also allow mixed arrays:
$h->table('people')->select()
->orderBy(['name' => 'asc', new Expression('func()')], 'desc')
->execute();
select * from `people` order by `name` asc, func() desc