prevent collectionId relation field change
This commit is contained in:
parent
21b152b58c
commit
f1a6a82bd3
|
@ -245,7 +245,28 @@ func (form *CollectionUpsert) checkRelationFields(value any) error {
|
||||||
|
|
||||||
options, _ := field.Options.(*schema.RelationOptions)
|
options, _ := field.Options.(*schema.RelationOptions)
|
||||||
if options == nil {
|
if options == nil {
|
||||||
continue
|
return validation.Errors{fmt.Sprint(i): validation.Errors{
|
||||||
|
"options": validation.NewError(
|
||||||
|
"validation_schema_invalid_relation_field_options",
|
||||||
|
"The relation field has invalid field options.",
|
||||||
|
)},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// prevent collectionId change
|
||||||
|
oldField := form.collection.Schema.GetFieldById(field.Id)
|
||||||
|
if oldField != nil {
|
||||||
|
oldOptions, _ := oldField.Options.(*schema.RelationOptions)
|
||||||
|
if oldOptions != nil && oldOptions.CollectionId != options.CollectionId {
|
||||||
|
return validation.Errors{fmt.Sprint(i): validation.Errors{
|
||||||
|
"options": validation.Errors{
|
||||||
|
"collectionId": validation.NewError(
|
||||||
|
"validation_field_relation_change",
|
||||||
|
"The relation collection cannot be changed.",
|
||||||
|
),
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
collection, err := form.dao.FindCollectionByNameOrId(options.CollectionId)
|
collection, err := form.dao.FindCollectionByNameOrId(options.CollectionId)
|
||||||
|
|
|
@ -291,6 +291,26 @@ func TestCollectionUpsertValidateAndSubmit(t *testing.T) {
|
||||||
}`,
|
}`,
|
||||||
[]string{"type"},
|
[]string{"type"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"update failure - changing relation collection",
|
||||||
|
"users",
|
||||||
|
`{
|
||||||
|
"schema": [
|
||||||
|
{
|
||||||
|
"id": "lkeigvv3",
|
||||||
|
"name": "rel",
|
||||||
|
"type": "relation",
|
||||||
|
"options": {
|
||||||
|
"collectionId": "wzlqyes4orhoygb",
|
||||||
|
"cascadeDelete": false,
|
||||||
|
"maxSelect": 1,
|
||||||
|
"displayFields": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
[]string{"schema"},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"update failure - all fields",
|
"update failure - all fields",
|
||||||
"demo2",
|
"demo2",
|
||||||
|
|
Loading…
Reference in New Issue