I am using TimestampBehavior and BlameableBehavior to set the usual created_at, created_by, etc attributes.
In my rules I use the unique validator where I combine an attribute with the created_by.
The problem I am facing is that created_by is populated after the validation thus validation passes when it should not.
Is there some easy-automated method the behaviors to kick-in before validation or I need to “customize” it (for instance on before validate force-call the behaviors expected to fill in values)?
1 Like
Solved,
as per the AttributeBehavior can specify on which even the values should be populated.
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'attribute1',
ActiveRecord::EVENT_BEFORE_UPDATE => 'attribute2',
],
In the blameable instance that would be
[
'class' => BlameableBehavior::class,
'attributes' => [
self::EVENT_BEFORE_VALIDATE => ['created_by', 'updated_by']
],
],
1 Like
Solution is perfect.
But created_by, updated_by should not be part of validation process as long this values are not coming from user input.