norman / ambry

Ambry is a database and ORM replacement for (mostly) static models and small datasets. It provides ActiveModel compatibility, and flexible searching and storage.
http://rubydoc.info/github/norman/ambry/master/frames
MIT License
57 stars 3 forks source link

Fixes validates with :uniqueness option #10

Closed tute closed 12 years ago

tute commented 12 years ago

Moved Ambry::Validations::Uniqueness to ActiveModel::Validations::UniquenessValidator to support validates :attr, :uniqueness => true syntax apart from validates_uniqueness_of (ActiveModel#validates looks for custom validations in ActiveModel::Validations::#{CustomValidator}Validator).

norman commented 12 years ago

I'm not sure using ActiveModel's namespace for this is a good idea, because then any other ActiveModel-compatible library that wants to define a uniqueness validation the same way will conflict with Ambry.

Although it's quite ugly, Active Model provides a solution for this, which would be to reference with validation with the namespace like this:

validates :"ambry/validators/uniqueness" => true

I think in this case aesthetics are less important than compatibility, particularly when there's already a more aesthetic alternative available by using validates_uniqueness_of rather than the validates form.

tute commented 12 years ago

I agree Norman, I'll close the Pull Request. Thanks for your time!

norman commented 12 years ago

Maybe we should at least document this? It's pretty counterintuitive and I only learned about this because your pull request made me look through the documentation.

tute commented 12 years ago

Should we add notes in the README, or in code? Now I don't remember if I've seen through code/tests this feature, maybe it's good to show it in the README (with the comment in question of course).