Skip to content
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

Widget validation: unique constraint #1069

Open
r1b opened this issue Feb 2, 2018 · 7 comments
Open

Widget validation: unique constraint #1069

r1b opened this issue Feb 2, 2018 · 7 comments

Comments

@r1b
Copy link

r1b commented Feb 2, 2018

Per discussion in #1035

- Do you want to request a feature or report a bug?

Feature.

- What is the current behavior?

There is no way to enforce unique constraints on collection fields.

- What is the expected behavior?

I propose a validation unique a la pattern to enforce unique constraints.

@erquhart
Copy link
Contributor

erquhart commented Feb 2, 2018

Seems like this should apply in specific contexts, such as a list widget. There's also the issue of widget values not necessarily being the same type. Can you share, abstractly if necessary, what your use case is? Might help clarify things a bit.

@cameron-yee
Copy link

I would use this feature too. My use case is to use a number (int) field as a sort order field to override a default sort. I'm building a react app that will query a collection of people, and sort by last name by default. I want a number field to specify if I want a person sorted in a different order. For example, put sortOrder field to 1 if I want a person at the beginning of my list regardless of last name.

@erquhart
Copy link
Contributor

erquhart commented Apr 2, 2019

@r1b I just saw the original issue where I asked you to create this issue, so I'm betting my comment above was bewildering 😑

I did think of some problems with using field validation to enforce uniqueness: we would be comparing against the entire collection, which can have an arbitrary number of entries, so it could bog down the CMS for large sites. Also, any of those entries may have changed in the repo since the CMS last downloaded them. These are possible to handle, as I've long thought we need to check for changes for certain operations anyway, but this feature will take some effort to implement.

@cameron-yee you can already provide sort override logic this way if you're not picky about the order of persons who should appear at top. Eg. everyone in last name order, but everyone with a given field set to a given value is included first. This logic would live in your templates, the CMS would just be used to flip the "sort first" switch for a given entry. Full manual sorting is covered in #475.

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@erquhart
Copy link
Contributor

We can use indexing to handle this in a performant way (thoughts on indexing as non-required persistent metadatain #1669). Worth keeping open for a potential solution.

@Darksoulsong
Copy link

@erquhart All my blog posts have a "featured" flag. I'd like the other posts to be unchecked once a new featured post is set. Would that be a use case for this? If not, is it possible to accomplish this another way?

@erquhart
Copy link
Contributor

@Darksoulsong I wouldn't expect this feature to enforce uniqueness by changing existing values in multiple posts, only by changing the value in question to ensure it's uniqueness.

The best way to do this from a data architecture standpoint is to keep the featured post in a separate file. Could be a file that already has other general site/global data. And then you could edit that file with the CMS today, no new feature needed.

If you go this route, use the relation widget to search for the post you want to set as featured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants