title: Sequelize insert into join table (many-to-many)
body: <p>I set up two models in sequelize that have a many-to-many relationship. Sequelize created the join table correctly, but I'm not able to insert into it. I've been poring over this section of the docs: <a href="http://docs.sequelizejs.com/en/latest/docs/associations/#creating-with-associations" rel="noreferrer">http://docs.sequelizejs.com/en/latest/docs/associations/#creating-with-associations</a> but I can't get anything to work based on their examples. They don't have a many-to-many example, unfortunately. </p>
  
  <p>Next I tried to use the setModel functions, and that's producing an error from deep in the sequelize code which I can't figure out. That code is below.</p>
  
  <p>My two models are Coin and Ledger.</p>
  
  <pre><code>Ledger.findById(22).then(ledger=&gt;{
      var c1 = Coin.findById(1);
      var c2 = Coin.findById(2);
      ledger.setCoins([c1,c2]).then(sc=&gt;{
          console.log(sc);
      });
  });
  </code></pre>
  
  <p>My models are related to each other using this code:</p>
  
  <pre><code>Ledger.belongsToMany(Coin,{ through: 'ledger_coin'});
  Coin.belongsToMany(Ledger, {through: 'ledger_coin'});
  </code></pre>
  
  <p>Can anyone give me some suggestions or point me on the right track for either using the <code>get</code> functions or the association options to write to the join table? I could write a custom function but I know there must be a way to do it.</p>