Create a gist now

Instantly share code, notes, and snippets.

Embed
CakePHP3 ORM match against 2 tags with LIKE, at least those 2 need to be m:n assigned, else no result.
<?php
if (array_key_exists('device_tags', $queryParams)
&& is_array($queryParams['device_tags'])
) {
foreach ($queryParams['device_tags'] as $queryParam) {
$subquery = $this->Devices->find()
->select(['Devices.id'])
->innerJoinWith('DevicesDeviceTags.DeviceTags', function ($qry) use ($queryParam) {
return $qry->where(['DeviceTags.identifier LIKE' => $queryParam]);
});
$qry->where(['Devices.id IN' => $subquery]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment