Grails domain class fields nullable validator decided by other fields
例如,我有一个名为:
的域类
1 2 3 4 5 6 7 8 | class Employee { boolean belongToDepartment Department department static constraints = { department ???? } } |
我想为部门写一个验证器,如果字段belongToDepartment为真,部门不为空,否则部门可以为空。
我不确定这是否有意义?
您可以在
1 2 3 4 5 | static constraints = { department nullable: true, validator: {dep, obj -> return !(obj.belongToDepartment && !dep) } } |