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

Enum constraints don't constrain anything #105

Open
maxime-rainville opened this issue Sep 9, 2019 · 2 comments
Open

Enum constraints don't constrain anything #105

maxime-rainville opened this issue Sep 9, 2019 · 2 comments

Comments

@maxime-rainville
Copy link

SilverStripe 4 DBEnum are created as table constraint. Those constraints are created using the following SQL statement.

ADD CONSTRAINT "ClassNamesUpgrade_ClassName_check" check ("ClassName" in ('App\MySite\FooBar', null))"

The only problem is that when you stick null in the list of allowed values, it seems to accept any other values ... which kind of defeats the entire purpose of setting the constraint in the first place.

Note that this is only a problem if you bypass the ORM to set invalid data in your enum column.

There's some related RFC about dropping ENUM support altogether silverstripe/silverstripe-framework#8401 so this might not be worth fixing.

@maxime-rainville maxime-rainville changed the title Enum constraint don't constrain anything Enum constraints don't constrain anything Sep 9, 2019
@dnsl48
Copy link
Contributor

dnsl48 commented Sep 23, 2019

Meanwhile I suggest we update the constraint to something like check ("fld" in ('a', 'b') or "fld" is null)

@dnsl48
Copy link
Contributor

dnsl48 commented Sep 25, 2019

After patching this up we'll also need to follow up on #104 (comment) and add a negative test.

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

2 participants