MCPcopy
hub / github.com/pocketbase/pocketbase / checkFieldDuplicates

Method checkFieldDuplicates

core/collection_validate.go:245–288  ·  view source on GitHub ↗
(value any)

Source from the content-addressed store, hash-verified

243}
244
245func (validator *collectionValidator) checkFieldDuplicates(value any) error {
246 fields, ok := value.(FieldsList)
247 if !ok {
248 return validators.ErrUnsupportedValueType
249 }
250
251 totalFields := len(fields)
252 ids := make([]string, 0, totalFields)
253 names := make([]string, 0, totalFields)
254
255 for i, field := range fields {
256 if list.ExistInSlice(field.GetId(), ids) {
257 return validation.Errors{
258 strconv.Itoa(i): validation.Errors{
259 "id": validation.NewError(
260 "validation_duplicated_field_id",
261 fmt.Sprintf("Duplicated or invalid field id %q", field.GetId()),
262 ),
263 },
264 }
265 }
266
267 // field names are used as db columns and should be case insensitive
268 nameLower := strings.ToLower(field.GetName())
269
270 if list.ExistInSlice(nameLower, names) {
271 return validation.Errors{
272 strconv.Itoa(i): validation.Errors{
273 "name": validation.NewError(
274 "validation_duplicated_field_name",
275 "Duplicated or invalid field name {{.fieldName}}",
276 ).SetParams(map[string]any{
277 "fieldName": field.GetName(),
278 }),
279 },
280 }
281 }
282
283 ids = append(ids, field.GetId())
284 names = append(names, nameLower)
285 }
286
287 return nil
288}
289
290func (validator *collectionValidator) checkFieldValidators(value any) error {
291 fields, ok := value.(FieldsList)

Callers

nothing calls this directly

Calls 3

ExistInSliceFunction · 0.92
GetIdMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected