Skip to content

Commit

Permalink
fix(create): last object when auto-increment key
Browse files Browse the repository at this point in the history
Fix the criteria passed to the `findOne()` when getting the last object if the schema has an auto-increment PK. The result of the previous query is an array containing the desired object, but prior to this commit we were looking for the `seq` property on the array, not the inner object.
  • Loading branch information
citycide committed Feb 4, 2017
1 parent 3f7f662 commit 6c8acc1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function findLastObject (model, object) {
: model.ctx.knex(model.name).first().where({ [key]: object[key] })

return runQuery(model.ctx, query, true)
.then(res => hasIncrements ? model.findOne({ [key]: res.seq }) : res)
.then(res => hasIncrements ? model.findOne({ [key]: res[0].seq }) : res)
}

function findKey (schema) {
Expand Down

0 comments on commit 6c8acc1

Please sign in to comment.