Skip to content

Instantly share code, notes, and snippets.

@gtrias
Created July 27, 2015 16:01
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 gtrias/216f7131d08f4db3ccf1 to your computer and use it in GitHub Desktop.
Save gtrias/216f7131d08f4db3ccf1 to your computer and use it in GitHub Desktop.
Cakephp3 - Retrieve entity based on related entity conditions
<?php
...
$this->loadModel('Posts');
$posts = $this->Posts
->find('all')
->limit(6)
->contain([
'Filed.Files',
'Filed.Thumbs',
'Filed.Filedtypes'
])
;
if ($center_id) {
$posts->matching('Centers', function ($q) use ($center_id) {
return $q->where(['Centers.id' => $center_id]);
});
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment