MCPcopy
hub / github.com/pocketbase/pocketbase / ValidateWithContext

Method ValidateWithContext

core/db.go:239–261  ·  view source on GitHub ↗

ValidateWithContext is the same as Validate but allows specifying the ModelEvent context.

(ctx context.Context, model Model)

Source from the content-addressed store, hash-verified

237
238// ValidateWithContext is the same as Validate but allows specifying the ModelEvent context.
239func (app *BaseApp) ValidateWithContext(ctx context.Context, model Model) error {
240 if m, ok := model.(PreValidator); ok {
241 if err := m.PreValidate(ctx, app); err != nil {
242 return err
243 }
244 }
245
246 event := new(ModelEvent)
247 event.App = app
248 event.Context = ctx
249 event.Type = ModelEventTypeValidate
250 event.Model = model
251
252 return event.App.OnModelValidate().Trigger(event, func(e *ModelEvent) error {
253 if m, ok := e.Model.(PostValidator); ok {
254 if err := m.PostValidate(ctx, e.App); err != nil {
255 return err
256 }
257 }
258
259 return e.Next()
260 })
261}
262
263// -------------------------------------------------------------------
264

Callers 1

ValidateMethod · 0.95

Calls 5

TriggerMethod · 0.80
PreValidateMethod · 0.65
OnModelValidateMethod · 0.65
PostValidateMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected