Skip to content

Instantly share code, notes, and snippets.

@inoas
Last active November 14, 2017 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inoas/368c0931066033493255f01fb8835a39 to your computer and use it in GitHub Desktop.
Save inoas/368c0931066033493255f01fb8835a39 to your computer and use it in GitHub Desktop.
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