Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Validations

Andreas Reischuck edited this page Sep 11, 2013 · 2 revisions

Model validations are handled separatly in contrast to rails, where they are attached at the model. Actually this is not completly true, because the validations get bound to the model at runtime, but at coding time, they can be found in either app/validations or domain/validations.

As you can see, here is also a difference in domain and standard validations, but its only a minor one. The controller uses only the standard validations and the domain server uses both. That is because the controller doesn’t know anything about the domain model and so it only can do some simple validations. But they are still needed, to speed up the response to the customer. You don’t need to create a command to check, if the user has typed a title for example.

Syntax for validations is pretty simple. First you need to make sure your validation module extends the ActiveSupport::Concern and includes the ActiveEvent::Validations.
In an included do...end wrapper you specify the validations exact the same like you would do in a rails model.
Finally, to create the binding to a command, you specifiy your targets as validation_target like this:

validation_target :'YourCommand'

in the module itself.

Clone this wiki locally