Reputation: 2306
How can I skip validation for a specific orm save on without uprooting my ORM models rules function?
I am using kohana 3.3
Upvotes: 0
Views: 969
Reputation: 325
In accepted answer, the use of $this->validation_required() function like à getter seems wrong (the default value of $required parameter is != NULL)
public function validation_required($required = TRUE)
{
if ($required === NULL)
{
// work as getter
return $this->_validation_required;
}
...
Upvotes: 0
Reputation: 5483
Take a look into rules()
method. You can easily add custom checks, like this one:
// required by default
protected $_validation_required = TRUE;
public function rules()
{
if ($this->validation_required())
{
// return all model rules
return array(
// default rules here
);
// or
// if extending model with existing rules
return parent::rules();
}
else
{
// skip validation
return array();
}
}
public function validation_required($required = TRUE)
{
if ($required === NULL)
{
// work as getter
return $this->_validation_required;
}
// set value
$this->_validation_required = (bool)$required;
return $this;
}
Of course, you can extend this code with custom rules for different events (insert/update etc).
PS. Also you can override check()
method and just return TRUE
when $this->validation_required() == TRUE
. But I'd preffer to send empty rules instead (cause rules()
was designed specially for customize, while check()
is a system method).
Upvotes: 3