MCPcopy
hub / github.com/pocketbase/pocketbase / checkUniqueName

Method checkUniqueName

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

Source from the content-addressed store, hash-verified

164}
165
166func (validator *collectionValidator) checkUniqueName(value any) error {
167 v, _ := value.(string)
168
169 // ensure unique collection name
170 if !validator.app.IsCollectionNameUnique(v, validator.original.Id) {
171 return validation.NewError("validation_collection_name_exists", "Collection name must be unique (case insensitive).")
172 }
173
174 // ensure that the collection name doesn't collide with the id of any collection
175 dummyCollection := &Collection{}
176 if validator.app.ModelQuery(dummyCollection).Model(v, dummyCollection) == nil {
177 return validation.NewError("validation_collection_name_id_duplicate", "The name must not match an existing collection id.")
178 }
179
180 // ensure that there is no existing internal table with the provided name
181 if validator.original.Name != v && // has changed
182 validator.app.IsCollectionNameUnique(v) && // is not a collection (in case it was presaved)
183 validator.app.HasTable(v) {
184 return validation.NewError("validation_collection_name_invalid", "The name shouldn't match with an existing internal table.")
185 }
186
187 return nil
188}
189
190func (validator *collectionValidator) ensureNoSystemNameChange(value any) error {
191 v, _ := value.(string)

Callers

nothing calls this directly

Calls 4

ModelMethod · 0.80
ModelQueryMethod · 0.65
HasTableMethod · 0.65

Tested by

no test coverage detected