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

Unique Index with Coalesce (or other SQL functions) #41

Open
ScottSmix opened this issue Sep 14, 2016 · 0 comments
Open

Unique Index with Coalesce (or other SQL functions) #41

ScottSmix opened this issue Sep 14, 2016 · 0 comments

Comments

@ScottSmix
Copy link

If I have an unique index, schema validations will create validates_uniqueness_of validators for my model. However, if my index definition contains a function like COALESCE it does not work properly.

For example:
CREATE UNIQUE INDEX "abc" ON "xyz" ("column1", "column2", COALESCE(column3, 0);

Schema validations will generate validates_uniqueness_of for column1 in scope of column2 and another for column2 in scope of column1. It completely ignores column3. The work around was to add the following in my model:

schema_validations except_type: :validates_uniqueness_of

IMHO, if a unique index contains a function, schema validations should not attempt to create an uniqueness validator (and note it in the log).

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

No branches or pull requests

1 participant