Repository navigation
Closed
Labels
Description
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.15 (or put your version here)
Steps to reproduce or a small repository showing the problem:
I have 2 models
category.entity.ts
@Entity()
export class BlogCategoryEntity {
@PrimaryGeneratedColumn()
id: number;
@Index()
@Column({unique: true})
alias: string;
@Column()
title: string;
@OneToMany(type => BlogPostEntity, post => post.category)
posts: BlogPostEntity[]
}post.entity.js
@Entity()
export class BlogPostEntity {
@PrimaryGeneratedColumn()
id: number;
@Index()
@Column({unique: true})
alias: string;
@Column()
title: string;
@Column('text')
description: string;
@Column({type: 'text', nullable: true})
text: string;
@Index()
@Column()
isPublished: boolean;
@Index()
@Column()
publishedAt: Date;
@Column()
categoryId: number;
@ManyToOne(type => BlogCategoryEntity, category => category.posts, {eager: true, nullable: false, onDelete: 'CASCADE'})
@JoinColumn()
category: BlogCategoryEntity;
}When i filter query by category_id, everything is ok:
const [rows, count] = await this.repository.findAndCount({
skip: query.skip,
take: query.take,
where: {
category: {
id: 1
}
}
});But, filter works only by primary nested field. Filtering by other fields don't work:
const [rows, count] = await this.repository.findAndCount({
skip: query.skip,
take: query.take,
where: {
category: {
alias: 'test'
}
}
});SELECT
"BlogPostEntity"."id" AS "BlogPostEntity_id",
"BlogPostEntity"."alias" AS "BlogPostEntity_alias",
"BlogPostEntity"."title" AS "BlogPostEntity_title",
"BlogPostEntity"."description" AS "BlogPostEntity_description",
"BlogPostEntity"."text" AS "BlogPostEntity_text",
"BlogPostEntity"."isPublished" AS "BlogPostEntity_isPublished",
"BlogPostEntity"."publishedAt" AS "BlogPostEntity_publishedAt",
"BlogPostEntity"."categoryId" AS "BlogPostEntity_categoryId",
"BlogPostEntity_category"."id" AS "BlogPostEntity_category_id",
"BlogPostEntity_category"."alias" AS "BlogPostEntity_category_alias",
"BlogPostEntity_category"."title" AS "BlogPostEntity_category_title"
FROM "blog_post_entity" "BlogPostEntity"
LEFT JOIN "blog_category_entity" "BlogPostEntity_category"
ON "BlogPostEntity_category"."id"="BlogPostEntity"."categoryId"
WHERE "BlogPostEntity"."categoryId" = ? -- PARAMETERS: [null]Are there options to implement this?
Reacted by Robert, Vivian, Vlad Poluch, Sergey Kuznetsov, anca, Adhitya Rahman, hpalic1, Robert Pitt, Alexey Gerasimov, Dominic Preap and 39 more
Reacted by Shafik Amin, chenwenqin, Petr, Rea, Rahul and Vladimir Avdeev
Activity
vivirancy commentedon May 29, 2019
@trixden Did you find any way around this yet? I just ran into this exact issue today and so far have not found a clean work around.
trixden commentedon Jun 7, 2019
anitricks commentedon Jun 7, 2019
trixden commentedon Jun 7, 2019
anitricks commentedon Jun 7, 2019
trixden commentedon Jun 7, 2019
vivirancy commentedon Jun 10, 2019
It would be nice to see a solution that works with TypeORM. I would hate to replace an ORM in a production app just to get this working. So far I've had to avoid any nested where statements. If anything its actually produced some cleaner code, but it would be nice to have to omit certain records without added API endpoints/resolvers for each unique case.
haschu commentedon Jun 11, 2019
I guess this is more a feature request than a bug, because TypeORM doesn't seems to support nested where conditions, or am I wrong?
I can't find anything in the docs.
hector-chauran commentedon Jul 15, 2019
You can always use the query builder.
frieck commentedon Aug 8, 2019
So, Typeorm supports or not nested relations filtering??
Having the same problem here, but it is not clear if this is a bug (and will be fixed) or this is a desired feature...
haschu commentedon Aug 8, 2019
@frieck It depends on whether you want to use
FindOptionsorQueryBuilder. As forQueryBuilder, since you're able to build any query you like, you can filter nested relations as deep as you want. UsingFindOptions, this is currently not supported :/I submitted a feature request for this (#4280), but unfortunately there isn't much feedback yet.
As this feature was also crucial for my team, we started to implement a TypeOrm extension wrapper, that also supports nested relation filtering using
FindOptions. We're going to publish it here on GitHub (see also: #534) as soon as we can find some time - which is hopefully very soon :).frieck commentedon Aug 8, 2019
@haschu That feature is absolutely crucial! Even if
QueryBuildercan be used to build the most complex queries (and we use it alot!) some times it lacks for simplicity, and I believe theFindOptionswere built for that simplicity.Would be glad if I can take a look in your extension wrapper! I have no idea on how does it works...
Is there any workaround to fix that, or maybe we can just wait for your feature request to be released, or even your wrapper?
haschu commentedon Aug 8, 2019
I don't think there is a workaround - we actually did implement a custom
EntityandRepositorywith customFindOptionsto achieve this feature. Our extension is currently tied to in-house code, hence I cannot share it for now, but I'll do my best to outsource the essentials into a standalone project soon.Currently, the active TypeORM development is kind of on hold - but it sure will going on (#3267)
I strongly believe that eventually those feature are going to be implemented into TypeORM, we just have to wait a bit :)
chris-snow commentedon Aug 22, 2019
Oddly enough, nested relations filtering works when using findOne.
31 remaining items
haschu commentedon Oct 9, 2020
@imnotjames This isn't a bug, but a missing feature. See #4280 🙂
imnotjames commentedon Oct 9, 2020
I automatically added labels based in the first post of the issue
imnotjames commentedon Oct 15, 2020
I tested this a few different ways. This is supported already in some cases and this issue is a duplicate of a previous issue.
imnotjames commentedon Oct 15, 2020
Duplicate of #2707
vash72 commentedon Oct 16, 2020
Maybe i'm wrong but for me ins't supported @imnotjames
if i try with nested where
nicobytes commentedon Nov 9, 2020
Find with embedded entities doest work when runs SQL query, TypeORM take the obj like an id no like the embedded entity's attribute.
In the log:
In the
WHERE "AppointmentsCoaches"."appointmentId" = $1therefore return[]cc @vash72 @imnotjames
Note: I'm using the version
0.2.29YEMEAC commentedon May 3, 2021
still not working.
huybkdn23 commentedon May 24, 2021
Still not working now, we still need this feature
pundarikas commentedon May 29, 2021
Not working.
arayik-yervandyan commentedon Jun 16, 2021
Still not working . version ^7.1.5
Yuri-Ribeiro commentedon Jun 23, 2021
Still not working.
imnotjames commentedon Jun 23, 2021
Still a duplicate of #2707 - direct conversation there.