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

Make sure that unique fields are validated in impacted model instances #268

Open
ellmetha opened this issue Oct 12, 2024 · 0 comments
Open
Milestone

Comments

@ellmetha
Copy link
Member

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:

class User < Marten::Model
  field :id, :big_int, primary_key: true, auto: true
  field :email, :email, unique: true, skip_unique_validation: true
end

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?
@ellmetha ellmetha added this to the v0.6.0 milestone Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant