title: How can I update a through-NM-attribute in sequelize?
body: <p>I've read <a href="https://stackoverflow.com/questions/32689275/how-can-i-update-an-attribute-in-a-through-table">this</a> question and it didnt' help me, so I'm asking my own:</p>
  
  <p>Let's suppose I have 2 tables joined by a NM through table using Sequelize and MariaDB:</p>
  
  <pre><code>User &lt;-- UserItem --&gt; Item
  </code></pre>
  
  <p>A single User can have many Items, and a single Item can belong to many Users. But I need a custom through attribute to store the quantity of the Item, let's call it Apples. So, according to the <a href="http://docs.sequelizejs.com/en/latest/docs/associations/#belongs-to-many-associations" rel="nofollow noreferrer">docs</a>, this will be the definition:</p>
  
  <pre><code>var UserItem = Sequelize.define('UserItem', {
    quantity: DataTypes.INTEGER
  }, 
    timestamps: false
  });
  models.Item.belongsToMany(models.User, {through: 'UserItem'});
  models.User.belongsToMany(models.Item, {through: 'UserItem'});
  </code></pre>
  
  <p>And then I add a new relationship with the through attribute like this:</p>
  
  <pre><code>User.addItem(item, { quantity: 0 });
  </code></pre>
  
  <p>This works as expected. But, what if I need to update the quantity of an Item? I could do the following:</p>
  
  <pre><code>User.addItem(item, { quantity: 20 });
  </code></pre>
  
  <p>And the quantity of my Item will be updated to 20 in case of existing, and inserted otherwise. I don't want this. I want something like that:</p>
  
  <pre><code>User.addItem(item, { quantity: quantity + 1 });
  </code></pre>
  
  <p>But due to the impossibility to make queries to the join tables, I am unable to get the particular NM row for updating using the previous value.</p>
  
  <p>How can I achieve this? Thanks in advance.</p>