Back to Objection Js

Custom id column

doc/recipes/custom-id-column.md

3.1.5469 B
Original Source

Custom id column

Name of the identifier column can be changed by setting the static idColumn property of a model class. Composite key can be defined by using an array of column names.

js
class Person extends Model {
  static get idColumn() {
    return 'person_id';
  }
}

Composite key:

js
class Person extends Model {
  static get idColumn() {
    return ['someColumn', 'someOtherColumn'];
  }
}