Skip to content

Use cases for intent based CRUD hooks

Raymond Feng edited this page Mar 9, 2015 · 14 revisions

We recently received some feedbacks on the intent-based CRUD hooks.

There are issues and ideas raised. We would like to fully understand the use cases to decide what's the best way to enhance the hook apis, especially the ctx structure. Community input is critical to make the exercise successful. Please contribute your use cases below.

There are different types of methods that trigger a hook function:

  1. prototype methods, such as updateAttributes, save, and delete. They work on a given model instance.
  2. static methods, such as create, updateAll, and deleteAll. They work on the a given model class.

There are a few categories I can see:

  1. In a before hook, perform additional operations.
  2. In a before hook, run some validations and fail fast.
  3. In a before hook, change/transform the input to the target DB operation.
  4. In a after hook, perform additional operations based on the outcome of the CRUD.
  5. In a after hook, change/transform the output from the target DB operation so that the callback/promise will receive a modified result.

Use cases from Raymond:

  • Calculate a license key for a subscription record before it's save to the DB. The license key is derived from a
Clone this wiki locally