2011-05-06 4 views
0

Quelle est la bonne façon de faire quelque chose comme ça avec Grails:validation Grails dépendant d'autres attributs

class myDomainThing { 
    String description 
    MyOtherDomainThing otherThing 

    static constraints = { 
    description(nullable:if(otherThing)) 
    otherThing(nullable:if(description)) 
    } 
} 

Je suis donc soit veux qu'il y ait un lien vers le otherDomainThing ou je veux une description de chaîne.

Répondre

2

Vous devez utiliser la validation Grails personnalisé à l'aide de la validator

static constraints = { 
    description(validator: { 
     return otherThing and !description 
    }) 
} 
0

vous devez utiliser un validateur personnalisé

static constraints = { 
    description validator: { val, obj -> 
    if(otherthing && val) { 
     false 
    } 
    else { 
     true 
    } 
    } 
} 

évidemment un peu pseudocode là autour otherthing