title: Sequelize Model - Delete item with belongsToMany n:m association
body: <p>I'm attempting to set up a DELETE route for my app, which uses Sequelize with a Postgres db. I have two different models, "Product" and "Interest" (think of Interest as a sort of category or tag). Products can have multiple Interests and Interests can have multiple Products, so I'm using a <code>belongsToMany</code> association. As a result, I have three tables: <code>Products</code>, <code>Interests</code>, and <code>ProductInterests</code>. Here's how I have the associations set up:</p>
  
  <p>For Products:</p>
  
  <pre><code>Product.belongsToMany(models.Interest, {
      foreignKey: 'productId',
      through: models.ProductInterest,
      as: 'interests',
      onDelete: 'CASCADE',
      hooks: true
  });
  </code></pre>
  
  <p>For Interests:</p>
  
  <pre><code>Interest.belongsToMany(models.Product, {
      through: models.ProductInterest,
      as: 'products',
      foreignKey: 'interestId',
      onDelete: 'CASCADE',
      hooks: true
  });
  </code></pre>
  
  <p>And this is the method being called in my controller for Products:</p>
  
  <pre><code>destroy(req, res) {
      return Product
          .findById(req.params.productId, {
              include: [
                  {
                      association: Product.associations.interests
                  }
              ]
          })
          .then((product) =&gt; {
              if (!product) {
                  return res.status(404).send({
                      message: 'Product not found'
                  });
              }
              return product
                  .destroy()
                  // I've also tried the following:
                  // .destroy({
                  //    truncate: true,
                  //    cascade: true
                  // })
                  .then(() =&gt; res.status(204).send())
                  .catch(error =&gt; res.status(400).send(error));
          })
          .catch(error =&gt; res.status(400).send(error));
  </code></pre>
  
  <p>This causes an infinite loops, with these queries being logged:</p>
  
  <pre><code>Executing (default): SELECT "Product"."id", "Product"."title", "Product"."brand", "Product"."url", "Product"."imageUrl", "Product"."currentPrice", "Product"."male", "Product"."female", "Product"."asin", "Product"."storeName", "Product"."createdAt", "Product"."updatedAt", "ProductInterest"."createdAt" AS "ProductInterest.createdAt", "ProductInterest"."updatedAt" AS "ProductInterest.updatedAt", "ProductInterest"."interestId" AS "ProductInterest.interestId", "ProductInterest"."productId" AS "ProductInterest.productId" FROM "Products" AS "Product" INNER JOIN "ProductInterests" AS "ProductInterest" ON "Product"."id" = "ProductInterest"."productId" AND "ProductInterest"."interestId" = 1;
  Executing (default): SELECT "Interest"."id", "Interest"."name", "Interest"."createdAt", "Interest"."updatedAt", "ProductInterest"."createdAt" AS "ProductInterest.createdAt", "ProductInterest"."updatedAt" AS "ProductInterest.updatedAt", "ProductInterest"."interestId" AS "ProductInterest.interestId", "ProductInterest"."productId" AS "ProductInterest.productId" FROM "Interests" AS "Interest" INNER JOIN "ProductInterests" AS "ProductInterest" ON "Interest"."id" = "ProductInterest"."interestId" AND "ProductInterest"."productId" = 6;
  </code></pre>
  
  <p>My intention is to a) delete the product in the Product table; b) delete the association record(s) in the ProductInterest table. I do not wish to delete the Interest itself if the Product is being deleted. Likewise, I do not wish to delete associated Product(s) if an Interest is deleted (just the association).</p>
  
  <p>I've tried several different permutations around this and can't find the right method. Any help would be appreciated.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Debugging the sequelize code a bit has led me to think that I shouldn't be using <code>cascade</code> like that. It's basically attempting to delete the product, which then (due to cascade) attempts to delete the Interest (which I don't want), which (due to cascade) then attempts to delete associated product, etc etc. Still not sure what the correct solution is.</p>