brianschardt / node_rest_api_mysql

MIT License
248 stars 140 forks source link

[Help] belongsTo relation #2

Closed darvesh closed 6 years ago

darvesh commented 6 years ago
'use strict';
module.exports = (sequelize, DataTypes) => {
  var Model = sequelize.define('Company', {
    name: DataTypes.STRING
  });

  Model.associate = function(models){
      this.Users = this.belongsToMany(models.User, {through: 'UserCompany'});
  };

  return Model;
};

Can you please explain why this is used in this.Users = this.belongsToMany(models.User, {through: 'UserCompany'});

How do I write belongsTo relation? I'm a beginner Thanks.

darvesh commented 6 years ago

Nevermind. I understood.