seb
seb

Reputation: 55

Modifying Grails constraints during runtime

The problem:

In my web application I defined some constraints. That I can save the domain class to "drafts" also when the constraint properties are not matching I set the constraint nullable to true. In the following process I can modify the object and after that to finalize the process I want to make a full validation. That means I want to add the nullable:false property.

Thanks

Upvotes: 2

Views: 703

Answers (1)

rxn1d
rxn1d

Reputation: 1266

  • Answer 1: Yes you probably can.
  • Answer 2: Yes.

So example:

    def user = new User()
    for(constraint in user.constraints) {
        constraint.value.setBlank(true)
        constraint.value.setNullable(false)
    }

For nested fields:

    for(constraint in user.someNestedFields.constraints) {
       ....
    }

But i would not recommend to do so. It looks like bad architecture. To save your domain entity without validation just call save(false).

Upvotes: 3

Related Questions