I have a table with three fields:
so for example:
I don’t want the user to be able to insert:
(1, 2, 3)
(1, 3, 2)
at the same time because
2, 3 is the same as
in other words:
option_b) should be unique such that
option_b can be interchanged without affecting the uniqueness
in other words I want to achieve the following using ecto:
You probably want a database constraint and a matching
check_constraint ecto validation. You can define the constraint in a migration.
I’d recommend a separate
options table with proper constraints. I see so many naively denormalized data models these days.
What would the proper constraints be?
I don’t want (user x) to choose the same two options twice (regardless of their order)
table with columns user_id, option_name, option_value
unique constraint on (user_id, option_value) and (user_id, option_name)
I want to achieve the following using ecto:
I was responding to your question about normalizing your data to avoid having to do that.