Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

Sequelize 多對多設定範例

Posted at 2016-07-21 Sequelize 

belongsToMany

User

1
2
3
4
User.belongsToMany(GameList, {
through: 'Favorite',
as: 'UserLike'
});

GameList

1
2
3
4
GameList.belongsToMany(User, {
through: 'Favorite',
as: 'UserLike'
});

Favorite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module.exports = {
attributes: {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
gameListId: {
type: Sequelize.INTEGER,
name: 'gameListId',
field: 'game_list_id'
},
userId: {
type: Sequelize.INTEGER,
name: 'userId',
field: 'user_id'
}
},
associations: function() {},
options: {
tableName: 'favorites',
classMethods: {},
instanceMethods: {},
hooks: {},
underscored: true
}
};

Share 

 Previous post: ATOM 心智圖外掛 Next post: 把 Sequelize 預設的駝峰命名改成底線命名 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo