Thursday 28 May 2020

Relation between Users and cryptodata Sequelize database

COIN.js module.exports = (sequelize, DataTypes) => { const Coin = sequelize.define('Coin', { cryptoName: DataTypes.STRING, }) return Coin } ​USER.jsmodule.exports = (sequelize, DataTypes) => { const User = sequelize.define('User', { firstName: DataTypes.STRING, lastName: DataTypes.STRING, email: { type: DataTypes.STRING, unique: true }, password: DataTypes.STRING }, { hooks: { beforeSave: hashPassword } }) return User } CoinUserRelations.js const User = require('./User.js') const Coin = require('./Coin.js') module.exports = (sequelize, DataTypes) => { const CoinUsersRelations = sequelize.define('CoinUsersRelations', { UserID: { type: DataTypes.INTEGER, references: { model: User, key: "UserID" } }, CoinID: { type: DataTypes.INTEGER, references: { model: Coin, key: "CoinID" } } }) CoinUsersRelations.belongsToMany(Coin, {as: 'Coin', foreignKey: 'CoinID'}) CoinUsersRelations.belongsTo(User, {as: 'User', foreignKey: 'UserID'}) return CoinUsersRelations } ​Hello, so my issue is a bit weirdCoinUsersRelations.belongsToMany called with something that's not a subclass ofSequelize.Model atFunction.belongsToMany ​and I was wondering why does it not understand that I want to create relations between these 2 tables..

Submitted May 28, 2020 at 07:02PM by gjellbi

No comments:

Post a Comment