You can use custom validator on department
to check if the boolean flag on the domain object is true and the department value is null. In that case it is a constraint failure, you can return false or an error code depending your need.
static constraints = {
department nullable: true, validator: {dep, obj ->
return !(obj.belongToDepartment && !dep)
}
}