Back to Sequelize

Deferrable

static/v3/api/deferrable/index.html

latest3.0 KB
Original Source

Deferrable() -> object

View code

A collection of properties related to deferrable constraints. It can be used to make foreign key constraints deferrable and to set the constraints within a transaction. This is only supported in PostgreSQL.

The foreign keys can be configured like this. It will create a foreign key that will check the constraints immediately when the data was inserted.

sequelize.define('Model', {
  foreign_id: {
    type: Sequelize.INTEGER,
    references: {
      model: OtherModel,
      key: 'id',
      deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE
    }
  }
});

The constraints can be configured in a transaction like this. It will trigger a query once the transaction has been started and set the constraints to be checked at the very end of the transaction.

sequelize.transaction({
  deferrable: Sequelize.Deferrable.SET_DEFERRED
});

INITIALLY_DEFERRED()

View code

A property that will defer constraints checks to the end of transactions.


INITIALLY_IMMEDIATE()

View code

A property that will trigger the constraint checks immediately


NOT()

View code

A property that will set the constraints to not deferred. This is the default in PostgreSQL and it make it impossible to dynamically defer the constraints within a transaction.


SET_DEFERRED(constraints)

View code

A property that will trigger an additional query at the beginning of a transaction which sets the constraints to deferred.

Params:

NameTypeDescription
constraintsArrayAn array of constraint names. Will defer all constraints by default.

SET_IMMEDIATE(constraints)

View code

A property that will trigger an additional query at the beginning of a transaction which sets the constraints to immediately.

Params:

NameTypeDescription
constraintsArrayAn array of constraint names. Will defer all constraints by default.

This document is automatically generated based on source code comments. Please do not edit it directly, as your changes will be ignored. Please write on IRC, open an issue or a create a pull request if you feel something can be improved. For help on how to write source code documentation see JSDoc and dox