I have done a Union in cakephp 3, however the union is doing it such that the buyers table records are shown first and then the tenants. Whereas i want it to be arranged based on created field in both Buyers and Tenants table so the latest records appears first. I tried doing that using epilog but gives an error
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'created' in 'order clause'
$tenant = $this->Tenants
->find('all', [
'fields' => ['Tenants.id', 'Tenants.created', 'Consumers.type'],
'conditions' => ['Tenants.client_id' => '1'],
'order' => 'Tenants.created desc'
])
->contain(['Consumers']);
$buyer = $this->Buyers
->find('all', [
'fields' => ['Buyers.id', 'Buyers.created', 'Consumers.type'],
'conditions' => ['Buyers.client_id' => '1'],
'order' => 'Buyers.created desc'
])
->contain(['Consumers']);
$results = $buyer->unionAll($tenant);
$results->epilog('ORDER BY created DESC LIMIT 7 OFFSET 7');