Situation
using Cake 3.2.6
in my CostItemsTable,
I have a buildRules
function
/**
* Returns a rules checker object that will be used for validating
* application integrity.
*
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
* @return \Cake\ORM\RulesChecker
*/
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['foreign_model_id'], 'ForeignModels'));
return $rules;
}
What I want
My CostItems Entity has 2 fields called foreign_model
and foreign_model_id
.
foreign_model_id
acts as the foreign key. foreign_model
acts as the Table that will be Parent to the CostItems table.
so a typical record can have foreign_model
as GeneralCostCategories and foreign_model_id
as 1.
What I tried
I tried to log the $this inside the buildRules function but I find nothing useful that allows me to dynamically change this rule.
$rules->add($rules->existsIn(['foreign_model_id'], 'ForeignModels'));
to
$rules->add($rules->existsIn(['foreign_model_id'], $entity->foreign_model));