Is it possible to define global conditions for Model ?
I have 2 Models: User
and Student
. In database both of them are using table u
You can use before find to modify all queries issued for a model:
function beforeFind(array $queryData) {
$queryData['conditions'][]['NOT'][$this->alias . '.parent_id'] = null;
return $queryData;
}
Be careful using this technique to not overwrite existing conditions (note the extra []
) otherwise a query for "not parent_id 2" becomes "not parent_id null".