title: Transaction rollback issue with knex
body: <p>I am trying to do mysql transactions using knex in node js. My SQL transactions look like this</p>
  
  <p>1- Check if company name exists, if yes then prompt error and rollback transaction.</p>
  
  <p>2- Check if email address exists, if yes then prompt error and rollback transaction.</p>
  
  <p>3- Insert into user, company and userroles tables and if error encountered rollback transaction.</p>
  
  <p>Now I observe that if error occurs inside nested then especially the lastone then transaction doesn't rollback instead it commits previous transactions.</p>
  
  <p>Here is my function code</p>
  
  <pre><code>return knex.transaction(function(t){
          return knex('company').where({ companyname: companyname }).select('companyid')
          .then(function(rows){
              if(rows.length &gt;= 1)
                  return Promise.reject('company already exist');
              return knex('Users').where({email: emailaddress}).select('userid')
          })
          .then(function(rows){
              if(rows.length &gt;=1 )
                      return Promise.reject('user already exist');
  
              return knex('Users').insert({username:username,email:emailaddress,passsword:password,creationtime:'2008-11-11 13:23:44',updationtime:'2008-11-11 13:23:44'},'userid')
  
          })
          .then(function(useridreturned){
              userid=useridreturned;
              return knex('company').insert({companyname:companyname,companytokens:100})
  
          })
          .then(function(companyidreturn){
              companyid=companyidreturn;
              return knex('userroles').insert({userid:userid[0],roleid:1,companyid:companyid[0]},'userrolesid')
  
          })
          .then(function(result){
              return Promise.resolve('Account Created');
          })
          .then(t.commit)
          .catch(t.rollback)
  
  
    })
  
  
  </code></pre>
  
  <p>Am I doing something wrong here ?</p>