validators: set xx_id when possible

This commit is contained in:
Yousong Zhou
2021-02-23 15:29:12 +08:00
parent 9f09117cd6
commit 2f7bd7a7a2
+7 -3
View File
@@ -576,9 +576,13 @@ func (v *ValidatorModelIdOrName) Validate(data *jsonutils.JSONDict) error {
if v.Model != nil {
val = v.Model.GetId()
}
if len(v.modelIdKey) > 0 && data.Contains(v.Key) {
data.Remove(v.Key)
data.Set(v.modelIdKey, jsonutils.NewString(val))
if v.modelIdKey != "" {
if data.Contains(v.Key) {
data.Remove(v.Key)
}
if val != "" {
data.Set(v.modelIdKey, jsonutils.NewString(val))
}
}
return nil
}