Skip to content

Return single item after updating/patching single item #423

@vladshcherbin

Description

@vladshcherbin
const user = await User.query().where('id', id).first()
const patchedUser = await user.$query().patch(input).returning('*')

In this example, user will return me a single user. Now I want to patch the user and return it. If I use the above, patchedUser will be an array of users so instead I have to use:

const patchedUser = await user.$query().patch(input).first().returning('*')

It feels a little bit weird to call first after updating already fetched single item.

Is it somehow possible that objection will automatically return single item if first was used before patching/updating?

I'm also interested in usage of limit with first() method in this issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions