MCPcopy
hub / github.com/pocketbase/pocketbase / onCollectionSave

Function onCollectionSave

core/collection_model.go:800–844  ·  view source on GitHub ↗
(e *CollectionEvent)

Source from the content-addressed store, hash-verified

798}
799
800func onCollectionSave(e *CollectionEvent) error {
801 if e.Collection.Type == "" {
802 e.Collection.Type = CollectionTypeBase
803 }
804
805 if e.Collection.IsNew() {
806 e.Collection.initDefaultId()
807 e.Collection.Created = types.NowDateTime()
808 }
809
810 e.Collection.Updated = types.NowDateTime()
811
812 // recreate the fields list to ensure that all normalizations
813 // like default field id are applied
814 e.Collection.Fields = NewFieldsList(e.Collection.Fields...)
815
816 e.Collection.initDefaultFields()
817
818 if e.Collection.IsAuth() {
819 e.Collection.unsetMissingOAuth2MappedFields()
820 }
821
822 e.Collection.updateGeneratedIdIfExists(e.App)
823
824 // normalize indexes table name
825 for i, raw := range e.Collection.Indexes {
826 parsed := dbutils.ParseIndex(raw)
827
828 // no need to normalize
829 if parsed.TableName == e.Collection.Name {
830 continue
831 }
832
833 parsed.TableName = e.Collection.Name
834
835 normalized := parsed.Build()
836 if normalized == "" {
837 continue // leave to the model validator to decide whether to return an error
838 }
839
840 e.Collection.Indexes[i] = normalized
841 }
842
843 return e.Next()
844}
845
846func onCollectionSaveExecute(e *CollectionEvent) error {
847 defer func() {

Callers

nothing calls this directly

Calls 11

NowDateTimeFunction · 0.92
ParseIndexFunction · 0.92
NewFieldsListFunction · 0.85
initDefaultIdMethod · 0.80
initDefaultFieldsMethod · 0.80
IsAuthMethod · 0.80
IsNewMethod · 0.65
NextMethod · 0.65
BuildMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…