title: findOrCreate on association table
body: <p><em>a similar question has been asked <a href="https://stackoverflow.com/questions/35707805/sequelize-findorcreate-on-the-through-table-on-belongstomany-association">here</a>, without a meaningful answer.</em></p>
  
  <p>Let's assume I have two tables,  Users and Projects.
  We want to have a n:m relationship between those two entities.</p>
  
  <p>We create </p>
  
  <pre><code>Project.belongsToMany(User, {
    through: UserProjectAssociation,
  });
  </code></pre>
  
  <p>Now, 
  if I do </p>
  
  <pre><code>myProject.addUser(1) // where projectId is 1 and userId is 1
  </code></pre>
  
  <p>this works.
  But if I try to do the exact same operation again, it fails (because projectId and userId needs to be, of course, unique.
  What I would like to do is </p>
  
  <pre><code>model.UserProjectAssociation.findOrCreate({
      where: {
        UserId: userId,
        ProjectId: projectId,
      }
    }
  </code></pre>
  
  <p>but I cannot find any reference on the findOrCreate api, on how to call it on an association table.</p>
  
  <p>What's the best way to do so? The expected result of the command would be the record (either just inserted or already existing).</p>
  
  <p>A Similar question would be for deleting a record. (if the record (userId:1, projectId:1) exists delete it, if not, don't do anything.</p>
  
  <p><strong>Answer</strong></p>
  
  <p>as pointed out by @piotrbienias in the comments, the syntax is exactly the same. Be sure that the database supports the Isolation level required. (In this case is SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ).</p>