CakePHP containable behaviour with conditions <p>From the following array, I need that <code>Exercise</code> array should contain <code>UserExercise</code> array only if in <code>UserExercise</code> array <code>user_id = 1</code></p> <pre><code>Array ( [0] =&gt; Array ( [ExerciseGroup] =&gt; Array ( [id] =&gt; 1 [name] =&gt; Chests [date_added] =&gt; 2015-01-30 00:00:00 [date_updated] =&gt; 2015-02-02 19:30:49 ) [Exercise] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 9 [group_id] =&gt; 1 [name] =&gt; Dumbell [date_added] =&gt; 2015-02-02 15:00:49 [date_updated] =&gt; 2015-02-02 19:30:49 [UserExercise] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 1 [user_id] =&gt; 2 [exercise_id] =&gt; 9 [sets] =&gt; 3 [reps] =&gt; 4 [mon] =&gt; [tue] =&gt; [wed] =&gt; 1 [thr] =&gt; [fri] =&gt; [sat] =&gt; [sun] =&gt; [date_added] =&gt; 2015-02-03 00:00:00 [date_updated] =&gt; 2015-02-03 19:18:56 ) ) ) [1] =&gt; Array ( [id] =&gt; 10 [group_id] =&gt; 1 [name] =&gt; Bench Press [date_added] =&gt; 2015-02-02 15:00:49 [date_updated] =&gt; 2015-02-02 19:30:49 [UserExercise] =&gt; Array ( ) ) [2] =&gt; Array ( [id] =&gt; 11 [group_id] =&gt; 1 [name] =&gt; Parallel [date_added] =&gt; 2015-02-02 15:00:49 [date_updated] =&gt; 2015-02-02 19:30:49 [UserExercise] =&gt; Array ( ) ) ) ) ) </code></pre> <p>ExerciseGroup Model</p> <pre><code>&lt;?php class ExerciseGroup extends AppModel { public $name = 'ExerciseGroup'; public $actsAs = array('Containable'); public $hasMany = array('Exercise' =&gt; array( 'className' =&gt; 'Exercise', 'foreignKey' =&gt; 'group_id', 'dependent' =&gt; true )); } ?&gt; </code></pre> <p>Exercise Model:</p> <pre><code>&lt;?php class Exercise extends AppModel { public $name = 'Exercise'; public $actsAs = array('Containable'); public $hasMany = array('UserExercise' =&gt; array( 'className' =&gt; 'UserExercise', 'foreignKey' =&gt; 'exercise_id', 'dependent' =&gt; true )); } ?&gt; </code></pre> <p>Controller Query I tried:</p> <pre><code>$this -&gt; paginate = array( 'conditions' =&gt; array(), 'contain' =&gt; array('ExerciseGroup' =&gt; array('conditions' =&gt; array('Exercise.UserExercise.user_id' =&gt; 1))), 'recursive' =&gt; 2, 'limit' =&gt; $this -&gt; ExerciseGroup -&gt; find('count') ); $exercises = $this -&gt; paginate('ExerciseGroup'); </code></pre> <p>The Error is get is <code>Model "ExerciseGroup" is not associated with model "ExerciseGroup" [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 342]</code></p>