title: Get last inserted id Sequelize
body: <p>I'm using Sequelize and I'm trying to get the last inserted ID in raw query.</p>
  <p>My query is</p>
  <pre><code>.query(Sequelize.Utils.format([&quot;insert into MyTable (field1, field2) values (?,?)&quot;, val1, val2])
  </code></pre>
  <p>The query is done perfectly, but the result on success event is <em>null</em>.</p>
  <p>Can someone help?</p>
  <p>Thanks.</p>
  <hr />
  <p>After some researches and zillions attempts, I understood how callee object work in sequelizeJs.</p>
  <p>please, correct me if my answer is wrong.</p>
  <p>the callee object needs this structure</p>
  <pre><code>{__factory:{autoIncrementField: 'parameterName'}, parameterName: '' }
  </code></pre>
  <p>in this case &quot;parameterName&quot; is the field that will store the new ID, sequelize looks for  __factory.autoIncrementField to set value of last inserted id into property with its value (value of __factory.autoIncrementField).</p>
  <p>so, my call to querys method would be</p>
  <pre><code>.query(sequelize.Utils.format(tempInsert), {__factory:{autoIncrementField: 'parameterName'}, parameterName: '' }, {raw: true})
  </code></pre>
  <p>this will result in object like that</p>
  <pre><code>{ __factory: { autoIncrementField: 'parameterName' }, parameterName: newInserted_ID }
  </code></pre>
  <p>thanks for all, and I hope this can help someone.</p>