I have to Tables: Users hasmany Memberhip
. I would like to build a query to get ALL Users but EACH User should only contain the FIRST Membership (after ordering).
$users = $this->Users->find()->contain([
'Membership' => function ($q) {
return $q->order([
'year' => 'ASC'
])->limit(1);
},
'Countries',
'Board',
]);
Seems good so far. The problem is, that this query only gets a single Membership alltogether. So in the end of all Users that are beeing fetched, only one User has one Membership.
How do I get CakePHP to fetch ONE Membership for EACH User?
Thanks!