Skip to content

Add ctx. isNewInstance to "before save" and "after save" hooks #838

Description

@pungoyal

Extend before save and after save hooks and add a new property ctx.isNewInstance (or similar).

This new property will have one of the following values for Model.updateOrCreate:

  • before save:
    • true when the data has not id and the method falls back to a regular create
    • true/false when a non-atomic implementation is used
    • undefined when an atomic implementation is used
  • after save:
    • true when the connector reported that a record was created
    • false when the connector reported that a record was updated
    • undefined when the connector did not report anythin

A thing to figure out: how to handle atomic findOrCreate, as it may fire the before save hook even if the model already exists?


The original issue description

Does it make sense to have a created event on model? Currently we have changed, but that fires for any changes to the model.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions