Unable to import models and create associations in sequelize

26 Views Asked by At

I am working in a Twitter-like backend system. There's a TweetService and a CommentService both in separate folders. Im using sequelize for the models and associations between models.The models which I want to associate are in different services and when I am trying to associate them Im getting the following error:

Tweet.belongsToMany called with something that's not a subclass of Sequelize.Model

The file structure for the models is : enter image description here enter image description here

Thus when I am trying to associate using the following code :

static associate(models) {
      // define association here
      this.belongsTo(Tweet,{
        foreignKey:'tweetId',
        onDelete:'CASCADE'
      })
    }

Im getting the error.I've imported the models in different folders using :

const {Tweet}=require('../../../TweetService/src/models/index')
0

There are 0 best solutions below