-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Unable to query data where relationship needs to be null using Repository method #8890
Comments
I have exactly the same issue. Any fix in the making? |
Same here. Version 0.3.6. @pleerock This is one of many issues of this kind opened here for the last couple of weeks. The problem is really serious. Looks like typeorm 0.3 is not production-ready yet. Are there any problems with the reproduce case or something? Do you need any assistance to fix this asap? |
Seems like the problem is in
} else {
let andConditions: string[] = []
for (let key in where) {
if (where[key] === undefined || where[key] === null) continue
} else if (relation) {
// if all properties of where are undefined we don't need to join anything
// this can happen when user defines map with conditional queries inside
if (typeof where[key] === "object") {
const allAllUndefined = Object.keys(where[key]).every(
(k) => where[key][k] === undefined,
)
if (allAllUndefined) {
continue
}
} |
@pleerock is it possible to prioritize this issue? |
A workaround for this issue that does not require any fix is to specify a @Entity()
export class Author {
@PrimaryColumn()
id: number
@OneToMany(() => Post, (post) => post.author)
posts: Post[]
}
@Entity()
export class Post {
@PrimaryGeneratedColumn()
id: number
@ManyToOne(() => Author, (author) => author.posts, {
nullable: true,
})
@JoinColumn({name: 'author_id'})
author: Author | null
@Column({
nullable: true,
select: false,
})
author_id: number | null
}
const posts = await dataSource.getRepository(Post)
.find({
relations: ['author'],
where: [
{
author_id: In([2, 3]),
},
{
author_id: IsNull(),
},
],
order: {
id: 'ASC'
}
}) |
@pleerock Is there any chance to get this fixed soon? I know it's vacation time but I, and I think many others, would appreciate it. |
* fix: allow where IsNull for ManyToOne relations Closes: typeorm#8890 * fix direct FindOperator queries on MTO relation * fix: allow FindOperator queries on OTO owner column * chore: prettier formating
Hi there, I may say that I'm facing an issue that is really close to this one, but mine still doesn't work, after having upgraded the package's version. These are my models:
Trying this code:
Returns all of my results. Even the ones with the I found and tried with
But my query actually returns an error (not in TS):
How can I filter on this field/relation? |
Hi, facing the same issue with a ManyToMany relation. I managed to work around the problem using a SelectQueryBuilder, but still it would be nice if it worked with the entity repository approach. Regards, |
Hi, Is there any news on this topic. This is a plausible use case to search for entities that do not have a specific relation! Kind regards, |
@s1njar The issue is closed and resolved. |
@m3c-ode Just use the latest version of typeorm. |
On 0.3.16 i still have the problem with a OneToOne. @GM-Alex Do you talk about the 0.4 alpha ? |
@growms 0.3.x fixed it for me. |
I've solved it with the reverse column const box = await AppDataSource.getRepository(BoxModel).find({
relations: {
pallet: true,
},
where: {
pallet: {
box_id: IsNull();
}
},
}); |
Love you man 🫶 |
Using
|
Issue Description
When I'm trying to query a model, where I need the relationship to be NULL, the SQL query doesn't add the WHERE IS NULL.
Expected Behavior
Actual Behavior
Steps to Reproduce
My Environment
Additional Context
Relevant Database Driver(s)
aurora-mysql
aurora-postgres
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
spanner
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: