Created
July 27, 2015 16:01
-
-
Save gtrias/216f7131d08f4db3ccf1 to your computer and use it in GitHub Desktop.
Cakephp3 - Retrieve entity based on related entity conditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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