references method

ColumnBuilder<T> references(
  1. Type table,
  2. Symbol column, {
  3. KeyAction? onUpdate,
  4. KeyAction? onDelete,
})

Adds a foreign-key reference from this column.

The table type must be a Dart class name defining a drift table. The column must be a Dart symbol with the same name as a column in the referenced table. In Dart, symbols can be created by prefixing an identifier with #.

In the following example, a Books table keeps a reference to the author of each book:

class Authors extends Table {
  IntColumn get id => integer().autoIncrement()();
  // ...
}

class Books extends Table {
  IntColumn get author => integer().references(Authors, #id)();
}

Important notice: In sqlite3, foreign keys are not enabled by default. When using foreign keys, remember to enable the option in the MigrationStrategy.beforeOpen callback:

beforeOpen: (details) async {
  await customStatement('PRAGMA foreign_keys = ON');
}

Implementation

ColumnBuilder<T> references(
  Type table,
  Symbol column, {
  KeyAction? onUpdate,
  KeyAction? onDelete,
}) {
  _isGenerated();
}