New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relational custom validation based on the length doesn't work as expected #13354
Comments
This is because the app is sending the "detailed" structure for updates (cc @Nitwel): {
create: [{ title: 'example' }],
update: [],
delete: []
} the |
Oh and the same will apply for o2m/m2m interfaces as well, as the logic is shared between those |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
is there any kind of workaround we might be able to use for now? |
No |
Linear: ENG-255 |
Just thought I'd pitch in to describe how I've just run into this issue myself. I was initially looking for a workaround for the absence of a one-2-one relation, or even a relation to a single object, as I've created a few of these for the 'compulsory' pages of my site. I'm exploring ways to enable user-created navigation, which when linking to internal pages, I would ensure content creators can link to existing pages/items. Tree-view would be ideal for this, except it only works for recursive relationships and so is only suitable for creating a nested same-type relationship, and not within a parent of a different type: E.g.
I also need to be able to link to multiple collections (for example, homepage, contact, articles, cookie policy), so O2M and M2M are off the table. This leaves me with M2A. For this to work, I've had to uncheck 'Treat as single object' for all the collections I wish to include in the M2A field as it's not possible otherwise (possible feature request here 😁). Then as I only need to link to one page only, I figured I would be clever by adding validation to check if the count of 'Internal Link' (as I've named it) is less than or equal to one. Unfortunately, I get a In the meantime, I've just had to settle for a note stating 'Maximum of one' under the M2A field despite you being able to add more. Then when it comes to constructing the nav in my front-end, I'll just grab the first item only from the array. Am I going about this the right way? Or is there another approach to this? A hard limit, or even the option to hide the 'Add existing' button conditionally would be great here. Other than that, absolutely loving Directus so far. Really great work, guys! |
if you haven't found a workaround yet, you can use flows to validate your m2m and m2a fields. Using scripts you have the possibility to intercept the payload with filter trigger and output errors in the ui. have a look: #16802 |
Describe the Bug
First of all: thanks for building Directus. We've been playing around with it a few days now and we love it!
However, we might have encountered a small bug. I'm trying to add some validation to a M2A field, but some things don't work as expected.
I've created three collections:
article
,page
andbanner
. In the banner collection I created the M2A field 'link' which should be required and it should only link to a maximum of one other record. I don't want multiple articles and/or pages to be linked at the same time for one banner record. Therefore, I've added a validation rule to that M2A field:However, this validation rule doesn't work as expected:
In the above screenshot I only linked one item (the article 'Foo') and this should be allowed according to the validation rule (length equals to 1).
When I link multiple items or nothing at all the validation is also triggered (which is expected).
To Reproduce
I've created a snapshot of the example data model so one can simply reproduce this.
Steps to reproduce:
The YAML snapshot
Errors Shown
N/A
What version of Directus are you using?
9.10.0
What version of Node.js are you using?
16.13.0
What database are you using?
Postgres 13
What browser are you using?
Chrome, Firefox, Safari
How are you deploying Directus?
Running locally
The text was updated successfully, but these errors were encountered: