(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']);
}
}
Since 3.4 is out (I run on 3.4.7) I had another look into this but didnt see any changes. Is this really fixed with the 3.4 or is the issue still open? I’m ready to test if there’s something to test
Test 1:
Added two tags to a post and saved => all good
Added three tags to a post and saved => validation message appears
Checked the database: Only the two relations were created in the table october_test_posts_tags
Now I created a relation config:
Changes within post > fields.yaml
tags:
label: Tags by Relation
commentAbove: Enter some tags here first, select them below
type: relation
mode: relation
useController: true
nameFrom: name
tab: Tags
Now the tag selection is not a taglist, it’s the relation widget where you can select.
Added a third tag to the opened post:
=> Tag was added to the tag form AND to the database already
Saved the post with three tags
=> an error message appears, but the tag is already added on the database level
=> the error should probably appear earlier, when the tag is submitted.