Collection override

Forest Admin allows customizing at a very low level the behavior of any given Collection via the usage of Collection Overrides.

Collection Overrides provide a powerful means to completely replace the default behavior of CUD operations (create, update, delete) for your Collections. This feature should be used with caution, as it directly affects the core operations on your data.

How it Works

In addition to the standard Collection functions:

  • create

  • update

  • delete

Collection Overrides allow you to define custom behavior that will entirely replace the default implementation of the create, update, and delete operations.

To define an Override for a Collection, you must specify:

  • The handler function that will be executed instead of the default operation.

The custom handler function will receive a context object containing relevant information for the operation, allowing for comprehensive control over the behavior of these CUD operations.

Context object reference

All override contexts provide access to:

  • collection - the current collection

  • datasource - the composite data source containing all collections

  • caller - information about the user performing the operation (see Collection Hooks for details)

Override-specific context properties

Override
Properties

Create

data - Array of records to create

Update

filter - Filter for records to update, patch - Partial update data

Delete

filter - Filter for records to delete

Setting Up Overrides

Overrides are declared similarly to hooks but are aimed at replacing an entire operation rather than augmenting its execution. However this can also be used to enrich the default behavior. Here's how to set up overrides in your Collection:

Custom Create Operation

To replace the default create operation, use override_create with your custom handler:

Custom Update Operation

To replace the default update operation, use with your custom handler:

Custom Delete Operation

To replace the default delete operation, use with your custom handler:

Basic Use Cases

Create over API

You might want to create the record with your custom API:

Modify data before update

You might want to modify payload data before update your record:

Implementing soft delete

Instead of actually deleting records, mark them as deleted:

Last updated

Was this helpful?