I’m trying to add an application rule that requires information from a different model/tabel
But how can i find data from within a model application rule?
public function buildRules(RulesChecker $rules)
{
...
$rules->add(function($entity, $options) {
$ThisModel = $this->Model->find('all')
->where(['key_id' => $entity->key_id ])
->count();
$AccosiatedModel = $this->AccosiatedModel->find()
->where(['key_id' => $entity->key_id ])->count();
if($ThisModel <= $AccosiatedModel) {
return true;
} else {
return false;
}
},'CutomRule');
return $rules;
}