-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Join relation with subquery #2074
Comments
no, there are no other ways =( |
Thanks for the reply, do you plan exposing something like |
we probably can do that, what is your use case? Something other then left or inner join? |
...
LEFT JOIN LATERAL (
SELECT * FROM "movies_actors"
WHERE "movieId" = "movie"."id"
LIMIT 5
) "movie_actors"
... Besides that, It's kinda useful to inject raw SQL for trying things out, debugging, etc. |
After trying out different things, it seems that I can't make subquery in join be treated as a relation. Am I missing something? |
because subquery isnt a relation. When you join |
I know it's not, but no matter how query was built, final result set can be treated as such. I've done it with Hibernate, where I'd write entire query with raw SQL and still get correctly mapped entity and it's relations. For example, I think this query should map photos to users: createQueryBuilder("user")
.leftJoinAndMapMany(
"user.photos",
qb => qb.from(Photo, "photo"),
"photo",
"photo.userId = user.id")
.geMany(); otherwise, what is the purpose of subquery in |
yeah that shall work however for map many "user.photos" is just a property name, it does not care if its a relation or something else. And btw most of times its really better to execute a separate queries and map the data in terms of both performance and code, so I was thinking to deprecate |
@pleerock I've abstracted over join and result transformer implementations, so I can do what I intended. Only thing that I can't do is lateral joins, can you add support for that? |
I'll left this open. Maybe in the future we will add that |
I don't know how you would like API for this to look like, but it's a very simple change |
I have the same question. Is this going to be applied in the near future? |
Is this going to be solved? It would be neat to have and would solve many issues in my code. |
Could you give a little example in this case @pleerock, how i need to execute a separate query to get same result? |
Hope this is what you looking for
Also on one of the entities, you can use options |
Do you have a source on this? Not doubting you, but I'd just like to read more about it. |
So you recommend to execute separate queries and I've read in another issue that you usually load your entities first and execute queries for things like relation counts etc and map that data to properties of your entities. Does this mean multiple db hits to collect the desired data? Or are you talking about creating subqueries and using It might be a really silly question. But many people I know just create giant queries with a lot of joins and execute them once. I can't say that is always performant but when there are more than one db hits, many people goes crazy. I mostly work as a front-end developer and don't have too solid knowledge about this kind of stuff. Can you clarify this a little bit more? (Maybe with some examples) Thanks! |
Anything new ? |
Anything new ? |
This One Work For Me
|
Issue type:
[x] question
Database system/driver:
[x]
postgres
TypeORM version:
[x]
0.2.0
Steps to reproduce or a small repository showing the problem:
I have the following relation
Movie -> Actors
:with
query.leftJoinAndSelect("movie.actors", "actor")
I get following query:which works fine. If I want to apply limit/offset to actors, I have to generate query like this:
I'm not sure how can I do this with query builder, if I use subquery in join, it seems I have to manually replicate what TypeORM does with respect to relationship type, join table column names,
ON
statements etc. in subquery. Is there any other way of doing it, where I have control over select statement inside join, but everything else stays the same?The text was updated successfully, but these errors were encountered: