Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level where clauses for nested includes ignored when using findByPk #13511

Open
s-devaney opened this issue Sep 21, 2021 · 4 comments
Open
Labels
type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.

Comments

@s-devaney
Copy link

  • Docs state that you can filter nested includes using a top-level where clause (using "$deeply.nested.field$" syntax)
  • However, top level where clauses appear to be ignored when using findByPk (I can understand why, I am not challenging this)
  • As a result the where clause is not applied in the query

Perhaps something needs to be added to the docs about this, or update the findByPk method to apply any nested where clause?

@wbourne0 wbourne0 added the type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference. label Oct 3, 2021
@wbourne0
Copy link
Member

wbourne0 commented Oct 3, 2021

Can you add some code samples for this? I don't fully understand the issue. Te generated SQL vs what you expect would also be super handy (if logging isn't already on, you can add logging: console.log to the query options)

@wbourne0 wbourne0 added the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Oct 3, 2021
@github-actions github-actions bot removed the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Oct 3, 2021
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added stale and removed stale labels Oct 27, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 4, 2021
@WikiRik WikiRik removed the stale label Nov 15, 2021
@AngelRivas0day
Copy link

AngelRivas0day commented Jul 25, 2023

I have the same problem.

This is the code that triggered the error for me:

let application = await Application.findByPk(applicationId, { where: { status: ['open','quoted'], seller_company_id: portal.company_id }, include: [{ model: Policyholder, },{ model: Rating, include: [ { model: RatingLV, where: { locale }, limit: 1, required: true, }, { model: Product, where: { active: 1, deleted: 0, }, include: { model: ProductLV, limit: 1, required: true, where: { locale }, }, }, ], }], });

And the MySQL query that it generates is the following:

SELECT <all the fields the query includes> WHERE Application.id = 646;

The top-level where conditions are completely ignored in the resulting query.

The only way I've figured out how to solve it is simple. Just change findByPk for findOne and include the ID in the where conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: docs For issues and PRs. Things related to documentation, such as changes in the manuals / API reference.
Projects
Development

No branches or pull requests

4 participants