title: Sequelize TypeError: phone.setUser is not a Function
body: <p>I'm a little lost and would appreciate any help with this. I have a M:M association between my users table and phones table through my <code>userPhones</code> table. </p>
  
  <p><strong>user.js</strong></p>
  
  <pre><code>  module.exports = (sequelize, DataTypes) =&gt; {
      const Users = sequelize.define('Users', {
      givenName: {
        type: DataTypes.STRING
      },
      sn: {
        type: DataTypes.STRING
      },
      mail: {
        type: DataTypes.STRING
      },
      title: {
        type: DataTypes.STRING
      },
      department: {
        type: DataTypes.STRING
      },
      sAMAccountName: {
        type: DataTypes.STRING,
        primaryKey: true
      },
      displayName: {
        type: DataTypes.STRING
      },
    }, {
      freezeTableName: true,
      timestamps: false
  
    });
    return Users; 
    };
  </code></pre>
  
  <p><strong>phone.js</strong>  </p>
  
  <pre><code>  module.exports = (sequelize, DataTypes) =&gt; {  
    const Phones = sequelize.define('Phones', {
      full_number: {
        type: DataTypes.STRING
      },
      telephone: {
        type: DataTypes.STRING
      },
      division_id: {
        type: DataTypes.FLOAT
     },
    }, {
      freezeTableName: true,
      timestamps: false
  
    });
  
    return Phones; 
    };
  </code></pre>
  
  <p><strong>db.js</strong></p>
  
  <pre><code>const Sequelize = require ('sequelize');
  
  const sequelize = new Sequelize('db', 'user', 'password', {
      host: '127.0.0.1',
      dialect: 'mssql',
      pool: {
          max: 9,
          min: 0,
          idle: 10000
      }
  });
  
  const db = {};
  
  db.Sequelize = Sequelize; 
  db.sequelize = sequelize; 
  
  //Gets models
  
  db.users = require('./models/users.js')(sequelize,Sequelize);
  db.phones = require('./models/phones.js')(sequelize,Sequelize);
  db.userPhones = sequelize.define('userPhones')
  
  //Sequelize Associations
  
  db.users.belongsToMany(db.phones, {through: 'userPhones'});
  db.phones.belongsToMany(db.users, {as: 'owners', through: 'userPhones'});
  
  // Sync SQL with Sequelize Models USE CAUTION
  sequelize.sync({alter:true});
  
  module.exports = db;
  </code></pre>
  
  <p><strong>phone post route for assigning a user to a phone</strong></p>
  
  <pre><code>const express = require('express'),
    router = express.Router(),
    db = require('../db')
    ;
  
  
  Phones = db.phones;
  UserPhones = db.UserPhones;
  
  // Single Phone User Assignment POST route
  
  router.route('/:id/users')
    .post((req, res) =&gt; {
      let users = req.body.UserSAMAccountName;
  
      Phones.findById(req.params.id)
        .then(function (phone) {
          if (!phone) {
            res.status(404).json({ message: 'record not found!' })
          }
          phone.setUsers([users])
          .then(associatedUsers =&gt; {
            res.status(200).json({ message: `${associatedUsers} added!`});
          })
  
        })
        .catch(function (err) {
          res.status(500).json({ error: `${err}`});
        })
  
    });
  
  
  module.exports = router;
  </code></pre>
  
  <p>I've previously been able to set assign phones to users and vice versa. I'm not exactly sure what has happened but the other day it just stopped working, and when I post to the API I am now getting:</p>
  
  <blockquote>
    <p>TypeError: phone.setUsers is not a function</p>
  </blockquote>
  
  <p>I've tried running <code>sequelize.sync({force:true});</code> just to test and see if re-initializing everything would fix things but I haven't seem to get things back on track. </p>
  
  <p>I've read about checking <code>Phones.instance.prototypes</code> but I'm not quite clear on how to go about finding that. </p>
  
  <p>Update: I failed to mention that there isn't any issue running this from my user route to assign a phone to a user. </p>
  
  <p><strong>user POST route for assigning a phone to a user</strong></p>
  
  <pre><code>const express = require('express'),
    router = express.Router(),
    db = require('../db')
    ;
  
    Users = db.users;
    UserPhones = db.UserPhones;
  
  // Single User-&gt;Phone Assignment POST route
  
  router.route('/:id/phones')
    .post((req, res) =&gt; {
      let phones = req.body.phoneID;
  
      Users.findById(req.params.id)
        .then(function (user) {
          if (!user) {
            res.status(404).json({ message: 'record not found!' })
          }
          user.setPhones([phones])
          .then(associatedPhones =&gt; {
            res.status(200).json({ message: `${associatedPhones} added!`});
          })
  
        })
        .catch(function (err) {
          res.status(500).json(err);
        })
  
    });
  
    module.exports = router;
  </code></pre>