(Rules array on the model which have this relation).
As soon as I select one example, the following message appears:
“The example creations field must be between 0 and 6 characters.”
So I wonder why it tells about characters here, the validation rule seem to apply in a strange way.
The second thing: The message should not appear if there’s just one model.
And the third thing: Even if the saving process on the Tag model throws this message, the new relation is already saved. So directly after I selected the entries from the form, configured within the config_relation, the new relation is created.
So… still not sure if I did something wrong or if this is still the wrong spot.
I can confirm the rule works if there’s no relation manager configured within config_relation.
I removed my config for the relation manager within the config_relation file and the applied rules worked. Since the relations are created on save of the model this seems reasonable.
If I applied the config_relation again and used the relation manager, the rule still worked on the save of the model and I got the expected error message if two many examples were attached.
But since the relation was created after clicking “Add Selected” within the relation manager modal, the example was already saved.
Do the rules have to be applied differently if a relation manager is used?
public function beforeValidate()
{
if ($this->exampleCreations()->withDeferred($this->sessionKey)->count() > 6) {
throw new ValidationException(['exampleCreations' => 'Too many']);
}
}