imdrasil/jennifer.cr

A way not to include Validation in the model?

Nicolab opened this issue · 4 comments

Hello,

I tested Jennifer a long time ago, happy to see that Jennifer is evolving well and is being actively maintained.
Thank you for this impressive work!
So I'm going to migrate to Jennifer.

One question, I do not wish to use the validator included in the base model. https://github.com/imdrasil/jennifer.cr/blob/master/src/jennifer/model/base.cr#L51

In order to include another validator.

Do you know a solution to override this module or cancel the inclusion (by a monkey patching or other)? Perhaps it would be possible to make the use of Jennifer's validations optional in a next version?

I glad to hear that you chose Jennifer 🎉 . Unfortunately you can't remove Jennifer::Model::Validation from the inheritance chain. Also you can't override #errors method and redefine @errors instance variable. But other than that validation mechanism can be changed. You need to have overrides for

  • #invalid? : Bool - return if record is invalid (should not perform any validation - just return a state)
  • #validate performs validation

Also as an alternative solution you can integrate your validator with Jennifer::Validations::Validator

Ok thanks, I will try to override or integrate with Jennifer::Validations::Validator. I'm a little afraid of the stability of the mixture.

Just a suggestion for a future release:
What do you think about to make the validator optional?
Need to include in each model (or a custom base model in user land inherited from Jennifer Model) or by using variable to leave the choice?
Example: Do not include if JENNIFER_VALIDATION = false is defined and false.

Just a suggestion, thanks :)

Hi, how is it going with integration of custom validation mechanism?

Hi imdrasil,

Not convenient, I dropped the idea.