-
-
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
.setRelationLoadStrategy("query") missing #8866
Comments
you are right, the documentation must be wrong. However I do not think that this implementation works at all. You can try setting the relationLoadStrategy to "query" by doing this:
However when I joined together our data model i got the following error:
|
Yes looks like an issue. Feel free to contribute! Just add a new method to SelectQueryBuilder called |
@pleerock this alone doesnt fix it since even when setting it via the expressionMap, the data seems to be loaded using joins and not multiple queries |
oh, I see. Current implementation works only when using |
Use this syntax, guys/girls (sucks that can't use querybuilder with it but this helped me do like a 100x increase in performance vs joins with 5 relations - tbh most of the stuff that querybuilder enables can be now achieved with .find too - just gotta be creative about it): let results = await this.repo.find({
relations: {
relationName: true, // Setting the relationName key to true in relations object forces to use query strategy!
},
}); |
Lately I was thinking about adding find operators |
@Rainson12 My workaround is using |
when using this workaround, you cannot do where on relation fields |
Actually, there are two ways to accomplish this. The first option is to pass the "where" condition into this.createQueryBuilder("post")
.setFindOptions({
relations: { experience: true, discount: { type: true } },
relationLoadStrategy: "query",
where: { discount: { type: { id: "1" } } },
}) Alternatively, you could use a join and then chain it with this.createQueryBuilder("post")
.setFindOptions({
relations: { experience: true, discount: { type: true } },
relationLoadStrategy: "query",
// where: { discount: { type: { id: "1" } } },
})
.innerJoin("post.discount", "discount")
.innerJoin("discount.type", "discountType")
.where("discountType.id = 1") Both methods produce the same behavior as using |
In my use case, there are several The problem with the second approach is that because it does not join the tables, relation alias is not defined. |
So what is the recommended solution for using the 'query' relationLoadStrategy in querybuilder? |
@pleerock do you have any plans to implement this in near future? |
I guess you forgot to put it to schema.prisma file:
|
Documentation Issue
What was unclear or otherwise insufficient?
Documentation for 0.3.0 (#8616) states the following:
However I cannot locate any reference to function 'setRelationLoadStrategy' in the 0.3.0 codebase. Is this a mistake and is not implemented?
The text was updated successfully, but these errors were encountered: