question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

asFindQuery() returns wrong builder for patchAndFetchById() operations

See original GitHub issue

I am using asFindQuery() to get the affected items in a static beforeUpdate() model hook that gets called when patchAndFetchById() is executed.

In this situation, asFindQuery() does not return a query that only selects the affected model items, it returns a query without a where clause, returning all model items of the given model class.

According to the docs, it should only return the model item with the given id?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
koskimascommented, Jan 1, 2021

I’ll start working on this now.

2reactions
fvinogradovcommented, Sep 23, 2020

I’m facing the same issue with updateAndFetchById. In code below asFindQuery executing returns all rows from DB:

class CampaignModel extends Model {
  static async beforeUpdate(ops) {
    await super.beforeUpdate(ops);
    const { asFindQuery, inputItems } = ops;
    const foundCampaigns = await asFindQuery().select('id', 'status');
  }
}

await CampaignModel
  .query()
  .updateAndFetchById(
    id,
    {
      status: 'PROCESSING',
    },
  );

As a temporal solution, for this model with beforeUpdate hook I replaced updateAndFetchById with

await CampaignModel
  .query()
  .update(
    {
      status: 'PROCESSING',
    },
  )
  .where({ id });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bountysource
asFindQuery () returns wrong builder for patchAndFetchById() operations.
Read more >
Vincit/objection.js - Gitter
I started transaction with PrescriptionMetaData Model and related PrescriptionSymptom Model by relationMappings as followings. Inside PrescriptionMetaData DAO.
Read more >
Mutating Methods | Objection.js
Creates an insert query. The inserted objects are validated against the model's jsonSchema. If validation fails the Promise is rejected with a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found