I have Users model which has many CovidTests.
I query all users containing only last CovidTests of each user with query below:
$users = $this->Users->find('all',
'contain' => ['Vaccinations', 'Healths', 'Vaccine1', 'Vaccine2', 'Groups', 'CovidTests' => function ($q) {
return $q->order(['test_date' => 'DESC'])
->limit(1)
;}]
,'order' => ['firstname' => 'ASC']
,'conditions' => ['is_deleted' => false ]
]);
The result is that I have all users, but only the 1 user content CovidTest while there are a lot of users has CovidTest in database.
That means the statement ->limit(1) applied to main function find of Users model, not the contained CovidTests
Is this a bug or ORM is designed that way?