-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Feature request: @Filter on a relation #704
Comments
Calling this: const posts = await orm.em.find(Post, { title: "Example" }, {
populate: ["comments"],
strategy: LoadStratetgy.JOINED, // you need to set it explicitly
}); will currently do a left join query - without inner join it does not make much sense, right? Also note you need to enable filters or set them as Afaik I am not sure about the |
Thanks for the response! I've updated my example: @Entity()
export class Post {
@OneToMany(() => Comment, comment => comment.post)
@FilterParent({ name: "enabledComments", cond: { enabledComments: true }, default: true })
@FilterChild({ name: "notDeletedComments", cond: { isDeleted: false }, default: true })
comments = new Collection<Comment>(this);
} const posts = await orm.em.find(Post, { title: "Example" }, {
populate: ["comments"],
strategy: LoadStrategy.JOINED
}); select * from "Post" as p
left join "Comment" as c on (p.id = c."postId")
and (p."enabledComments" = true)
and (c."isDeleted" = false);
It was my mistake, it should be a left join.
It's fixed in the example.
I've replaced |
Hi, just wanted to bump this, specifically in regards to adding support for extending the left joins in a LoadStrategy.JOINED with a specified filter - essentially so that it would produce the same result as if querying with LoadStrategy.SELECT_IN. So, given this code:
It would generate this:
This would also align the strategies so that they would produce the same result in both cases. |
I might be a bit late or missed a critical feature, but this one is essential for what we do in the company since almost all relations are normalised. |
This is also critical for my team. Are there any good workarounds in the meantime? Is it possible to get the same functionality with an @filter on the entity? Obviously this wouldn't be ideal, but for the short-term this would be great. |
@robbyemmert we managed to get around that by writing proper finders with leftJoinAndSelect and adding an andWhere clause. |
+1 |
Previously, the filters were applied only when using the select-in strategy, as part of the `where` condition. With this change, when using the joined strategy, filters will be also applied to the query, via `join on` conditions. Closes #704 Closes #2440 Signed-off-by: Martin Adámek <banan23@gmail.com>
Is your feature request related to a problem? Please describe.
I think it would be useful to be able to add filters to the
join
conditions.Describe the solution you'd like
It should generate a query like this:
See Hibernate docs (Example 19.2. Using @FilterJoinTable for filterting on the association table)
Describe alternatives you've considered
I've read about filters and
LoadStrategy.SELECT_IN
, but I thinkLoadStrategy.SELECT_IN
is bad for performanceThe text was updated successfully, but these errors were encountered: