-2
$query = $queryOne->unionAll($queryTwo)->order(['Headers.id' => 'desc']);

this is not working.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Akatuki
  • 3
  • 1

1 Answers1

0

You can try making View in Mysql to sort after UNION.

Otherwise there is no way to do that in Cake structure.

Sunny Kumar
  • 823
  • 6
  • 14
  • ok, I will create a view for it. thank you! – Akatuki Apr 21 '17 at 08:58
  • 1
    That's not correct, the CakePHP query builder comes with functionality to append SQL via the `epilog()` method. **http://stackoverflow.com/questions/29379579/how-do-you-modify-a-union-query-in-cakephp-3/29386189#29386189**. Also one could always utilize subqueries. – ndm Apr 21 '17 at 11:43
  • But by this way can we use pagination in that? – Sunny Kumar Apr 21 '17 at 12:39
  • Yes, you can. However unless you're using a subquery solution, using the paginator component will require to use a finder where you manually apply the order/limit/offset on the union query. Also you'd have to use a custom counter in order to count on the union query without the limiting epilog SQL applied. – ndm Apr 21 '17 at 16:47
  • I've updated my answer to the linked question with a subquery example... – ndm Apr 21 '17 at 18:18