geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

Inject validations and skip validations #174

Open FabricioFFC opened 10 years ago

FabricioFFC commented 10 years ago

I'm building a multi-step form, so the user fill the form per block. I want to know, if model supports skip validations [scenario 1] and inject validations [scenario 2].

Scenario 1: user fills the name and email, and the User model must be saved, even if there are validations to check other attributes presence.

Scenario 2: in the server side, I want to inject a validation to check if the email is unique in my database, and I'm doing this validation only in the server side, because I don't want to expose the validation to the client.

Can model support these scenarios?

ben-ng commented 10 years ago

I don't understand what you are trying to achieve with scenario 1. model has validation scenarios, which let you specify what operations (like a save, or fetch) should the validation be run on.

Regarding Scenario 2, model does not support uniqueness checking as a validator because that is an async operation and validation is sync. You should do this in your controller code.

FabricioFFC commented 10 years ago

In the scenario 1 the user will fill just a few fields, so I must validate just the fields filled, not all model validations. Can I do this using model?