title: Node.js - How to use Sequelize transaction
body: <p>I am a beginner with <code>sequelize</code> and cannot get the transactions to work. Documentation is unclear and makes the following example not able to adapt to my requirements. </p>
  
  <pre><code>  return sequelize.transaction(t =&gt; {
    // chain all your queries here. make sure you return them.
    return User.create({
      firstName: 'Abraham',
      lastName: 'Lincoln'
    }, {transaction: t}).then(user =&gt; {
      return user.setShooter({
        firstName: 'John',
        lastName: 'Boothe'
      }, {transaction: t});
    });
  
  }).then(result =&gt; {
    // Transaction has been committed
    // result is whatever the result of the promise chain returned to the transaction callback
  }).catch(err =&gt; {
    // Transaction has been rolled back
    // err is whatever rejected the promise chain returned to the transaction callback
  });
  </code></pre>
  
  <p>First I have to insert a tuple in 'Conto', then insert another tuple in 'Preferenze' and finally based on the 'tipo' attribute insert a tuple in 'ContoPersonale' or 'ContoAziendale'. </p>
  
  <p>If only one of these queries fails, the transaction must make a total rollback, commit.</p>
  
  <p>The queries are:</p>
  
  <pre><code>Conto.create({
          id: nextId(),
          mail: reg.email,
          password: reg.password,
          tipo: reg.tipo,
          telefono: reg.telefono,
          idTelegram: reg.telegram,
          saldo: saldoIniziale,
          iban: generaIBAN()
      })
  
  Preferenze.create({
          refConto: 68541
      })
  
  if (tipo == 0) {
          ContoPersonale.create({
          nomeint: reg.nome,
          cognomeint: reg.cognome,
          dataN: reg.datan,
          cf: reg.cf,
          refConto: nextId()
          }) 
          }
  else if (tipo == 1) { 
          ContoAziendale.create({
          pIva: reg.piva,
          ragioneSociale: reg.ragsoc,
          refConto: nextId()
          })
          }
  </code></pre>