Reputation: 15434
I have custom validation rule:
public function customRule($check)
{
}
Inside this rule I would like to access some model data (in database). Of course I can do it like this:
$this->id = 23;
$this->read();
But then all the data in current model will be overidden by read
function (I mean $this->data[$this->alias][...]
is overridden.
How I can get this data?
Upvotes: 0
Views: 414
Reputation: 4856
Just to note that if you want to get the full record of the data that is currently being validated it is always accessible in $this->data
inside the validation rule as opposed to $check which contains only the data in the currently validated field.
If you need to validate based on something that is stored in the DB, you can use $this->find()
or any of the Model's functions as you are in the Model.
I support @burzum 's answer +1.
Upvotes: 1
Reputation: 25698
Use a regular
$result = $this->find('first', array('conditions' => array($this->alias . '.' . $this->primaryKey => $id));
with the id in the find conditions. And work with the result, it is not overriding the data property.
Upvotes: 3