Sequelize 多對多設定範例
Posted at 2016-07-21 Sequelize
belongsToMany
User
1234
User.belongsToMany(GameList, { through: 'Favorite', as: 'UserLike'});
GameList
GameList.belongsToMany(User, { through: 'Favorite', as: 'UserLike'});
Favorite
123456789101112131415161718192021222324252627
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 }};
Previous post: ATOM 心智圖外掛 Next post: 把 Sequelize 預設的駝峰命名改成底線命名