mesaugat / express-api-es6-starter

Build APIs with Express.js in no time using ES6/ES7/ESNext goodness.

Home Page:https://express-api-es6-starter.herokuapp.com/api-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

help with idAttribute

duard opened this issue · comments

How can I set diferent idAttribute to my table ?

something like this.idAttribute: 'cpf';

Setting a different idAttribute is generally a bad idea. You can simply create another column which contains unique values and leave the idAttribute as it is.

Something like this should work but it might have it's consequences.

class User extends bookshelf.Model {
  get tableName() {
    return TABLE_NAME;
  }

  get idAttribute() {
    return 'cpf';
  }
}

I try this yesterday and not work for me
Do you sugest I mantain the column id and set unique to CPF ?

  get idAttribute() {
    return 'cpf';
  }

Yes that is the way to do it.