Hi everyone.
I have a Template model with following relations
class Template extends ModelBase
{
public function initialize()
{
$this->hasMany('id', 'Api\Modules\Template\Models\TemplateLanguage', 'template_id', ['alias' => 'TemplateLanguage']);
$this->hasMany('id', '\Api\Modules\Template\Models\TemplateRelation', 'related_template_id', ['alias' => 'TemplateRelationRelated']);
$this->hasMany('id', '\Api\Modules\Template\Models\TemplateRelation', 'template_id', ['alias' => 'TemplateRelationMain']);
$this->belongsTo('template_type_id', '\Api\Modules\Template\Models\TemplateType', 'id', ['alias' => 'TemplateType']);
$this->belongsTo('locked_by_user_id', '\Api\Modules\User\Models\User', 'id', ['alias' => 'UserLockedBy']);
$this->belongsTo('created_by_user_id', '\Api\Modules\User\Models\User', 'id', ['alias' => 'UserCreatedBy']);
}
}
In my TemplateRelation model I have following validators
class TemplateRelation extends ModelBase
{
public function validation()
{
$di = \Phalcon\DI::getDefault();
$validator = new Validation();
$validator->add(
'related_template_id',
new Digit([
"message" => $di['t']->_("template_relation.error.related_template_id_must be number")
]));
return $this->validate($validator);
}
}
The $di['t'] is my service for translation.
When in my controller I do
class TemplateController extends ControllerBase
{
public function updateAction(int $templateId
{
//some code with seting $template properties
$template->update();
}
}
And then TemplateRelation validators don't work. Anyone has any idea what I could do wrong?