With beforeFind (), you must return the $queryData array that you changed if you want to use it. This is your current problem.
public function beforeFind($queryData) { parent::beforeFind(); $queryData['conditions'] = array('client_id' => 2); return $queryData; }
However, you have a couple of other minor problems that can cause problems on the line.
You should not set conditions directly in your beforeFind () file, but add . What if you call a find with conditions? Consider this:
$this->MyModel->find('first', array( 'conditions' => array( 'MyModel.active' => 1 ) ));
You want find to use this condition, but also for your beforeFind (), to automatically return only the result for client_id = 2 , using your beforeFind (). Unfortunately, with this line in your beforeFind ():
$queryData['conditions'] = array('client_id' => 2);
You have just completely rewritten the conditions array and lost another condition MyModel.active = 1 .
You must also make sure that you indicate which model the field in the condition refers to. This is good practice, and future proof of your code, if you have two models that have a field called client_id . You can use $this->alias to get the current model alias, which will also allow your code to work if you used a different alias for the model.
So your final code should be:
public function beforeFind($queryData) { parent::beforeFind(); $queryData['conditions'][$this->alias . '.client_id'] = 2; return $queryData; }
source share