Objection.js: Suggestion - Where() using id shouldn't return an Array

Created on 17 Jul 2018  路  3Comments  路  Source: Vincit/objection.js

Since id is the primary key of an model, we shouldn't return an array from an query like this

const client = await Client.query()
            .where('id', request.auth.credentials.userId)

the id is unique, why not return the object instead of an array?

The same behavior should append with unique columns using objection-unique

All 3 comments

Why should Objection make such smart assumption on user's behalf and surprise him with inconsistent behaviour?
You can always use .first() explicitly.

@Ahlid To add to @kibertoad you can also use:

const client = await Client.query()
            .findOne('id', request.auth.credentials.userId)

thanks alot @heisian =)

findOne also lead me to findById that has the behavior I wanted

Was this page helpful?
0 / 5 - 0 ratings