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

Cannot query for related objects where the relation is NULL. #8945

Closed
tomasreimers opened this issue Apr 29, 2022 · 3 comments
Closed

Cannot query for related objects where the relation is NULL. #8945

tomasreimers opened this issue Apr 29, 2022 · 3 comments

Comments

@tomasreimers
Copy link
Contributor

Issue Description

Cannot query for related objects where the relation is NULL.

For example,

prod.manager.find(Book, {
where: {
author: IsNull(),
},
relations: ["author"],
})

Will simply query for all books (not adding any where relationship for "authorId IS NULL").

Expected Behavior

We would add the relationship of "authorId IS NULL".

Actual Behavior

We do not add the relationship of "authorId IS NULL".

Steps to Reproduce

  1. Create author table
  2. Create book table
prod.manager.find(Book, {
        where: {
          author: IsNull(),
        },
        relations: ["author"],
      })

My Environment

MacOS, TypeORM 0.35

Relevant Database Driver(s)

Postgres

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✅ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
@jczacharia
Copy link

The fix for this is in #9031

If you want a quick fix for this just go into node_modules/typeorm/query-builder/SelectQueryBuilder.js and add his code from this: https://github.com/typeorm/typeorm/pull/9031/files#diff-52bea788267888fdbb5f795f0dfb61504f16bd43e0afdfa28848abb4435121b5

I'm doing my builds locally so it's no issue for me but I would consider this a critical bug so hopefully this PR can get shipped soon.

@pleerock
Copy link
Member

duplicate of #8890

@tGeorgiy
Copy link

Many-To-Many find where Relation is Null still not working..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants