4 comments

[ 3.4 ms ] story [ 20.2 ms ] thread
One note when using this for form validation. If you have a multi-column unique index Phoenix will show the error for the field defined first in the constraint in the schema definition. This has tripped me up a couple of times for user input where the constraint is something like tag+post_id. If your form just has the tag input and you put post_id as the first item in the constraint the changeset will be invalid but no error will show.
That... sounds like a good candidate for a bug report/feature request.
Yea this has gotten me too. What I do now is specify the field I want the error on first in the constraint function, then manually set the index name.

It will still work exactly as expected if you provide the index name manually, even if it's not the same order as the constraint in the DB.