You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's ensure that unique fields are also validated in the models that make use of them.
Context
Right now model fields making use of the unique option are associated with a unique constraint at the database level. That said, this uniqueness is not explicitly validated by the framework at the moment: if a model record is validated with a field value that is already taken by another record, no validation errors are generated but a database error is likely to be raised.
This forces applications to manually (and systematically) implement uniqueness validations.
Proposition
Let's ensure that unique fields are automatically validated and let's make this the default behavior.
Ideally, it should be possible to disable this behaviour on a per-field basis (which could be useful if custom validations must be implemented). This could be done by specifying a skip_unique_validation: true option to the model definition:
classUser < Marten::Model
field :id, :big_int, primary_key:true, auto:true
field :email, :email, unique:true, skip_unique_validation:trueend
Questions
What about table unique constraints? For simplicity, should we assume that these don't imply any validations since they are explicitly defined as "DB unique constraints" in models?
The text was updated successfully, but these errors were encountered:
Description
Let's ensure that unique fields are also validated in the models that make use of them.
Context
Right now model fields making use of the
unique
option are associated with a unique constraint at the database level. That said, this uniqueness is not explicitly validated by the framework at the moment: if a model record is validated with a field value that is already taken by another record, no validation errors are generated but a database error is likely to be raised.This forces applications to manually (and systematically) implement uniqueness validations.
Proposition
Let's ensure that unique fields are automatically validated and let's make this the default behavior.
Ideally, it should be possible to disable this behaviour on a per-field basis (which could be useful if custom validations must be implemented). This could be done by specifying a
skip_unique_validation: true
option to the model definition:Questions
The text was updated successfully, but these errors were encountered: