added back relation filter reference support
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/go-ozzo/ozzo-validation/v4/is"
|
||||
@@ -211,6 +212,7 @@ func (f SchemaField) Validate() error {
|
||||
validation.Length(1, 255),
|
||||
validation.Match(schemaFieldNameRegex),
|
||||
validation.NotIn(list.ToInterfaceSlice(excludeNames)...),
|
||||
validation.By(f.checkForVia),
|
||||
),
|
||||
validation.Field(&f.Type, validation.Required, validation.In(list.ToInterfaceSlice(FieldTypes())...)),
|
||||
// currently file fields cannot be unique because a proper
|
||||
@@ -228,6 +230,20 @@ func (f *SchemaField) checkOptions(value any) error {
|
||||
return v.Validate()
|
||||
}
|
||||
|
||||
// @todo merge with the collections during the refactoring
|
||||
func (f *SchemaField) checkForVia(value any) error {
|
||||
v, _ := value.(string)
|
||||
if v == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(v), "_via_") {
|
||||
return validation.NewError("validation_invalid_name", "The name of the field cannot contain '_via_'.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitOptions initializes the current field options based on its type.
|
||||
//
|
||||
// Returns error on unknown field type.
|
||||
|
||||
@@ -298,6 +298,15 @@ func TestSchemaFieldValidate(t *testing.T) {
|
||||
},
|
||||
[]string{"name"},
|
||||
},
|
||||
{
|
||||
"name with _via_",
|
||||
schema.SchemaField{
|
||||
Type: schema.FieldTypeText,
|
||||
Id: "1234567890",
|
||||
Name: "a_via_b",
|
||||
},
|
||||
[]string{"name"},
|
||||
},
|
||||
{
|
||||
"reserved name (null)",
|
||||
schema.SchemaField{
|
||||
|
||||
Reference in New Issue
Block a user