LoginSignup
2
3

More than 5 years have passed since last update.

Sails.jsでプライマリキーをid以外のカラムに持たせる方法

Posted at

別システムからの移植だったり、政治的事情があったりして、id以外のカラムがプライマリキーになることがある。
ところがCoCなSails.jsではデフォルトの設定がidをプライマリキーに設定してある。
そんな時は、該当するテーブルのモデルでattributesを次のように設定すれば良い:

module.exports = {

  attributes: {
    id: {
      type: 'integer',
      columnName: 'user_id'  //DB上でuser_idとなってるカラムをsails上ではidとして扱う
    },
    //以下省略
  }

  //以下省略
};
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3