Skip to content
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

Support lateral join subqueries #3272

Closed
jjl opened this issue Apr 7, 2020 · 2 comments
Closed

Support lateral join subqueries #3272

jjl opened this issue Apr 7, 2020 · 2 comments

Comments

@jjl
Copy link

jjl commented Apr 7, 2020

Currently, ecto supports lateral joins for fragments, but not for subqueries.

To steal an example from the original lateral join thread:

post = Repo.one(
  from p in Post,
  where: p.id == 123,
  lateral_join: cs in subquery(
    from c in Comment,
    order_by: [desc: c.inserted_at],
    where: c.post_id == p.id,
    limit: 5
  ),
  preload: [comments: cs]
)

The primary difficulty seems to come from the nested invocation of from (or to look at it another way, informing the subquery of some parent bindings.

I would be willing to put some work towards this, but I'd need guidance as I'm not very familiar with the ecto codebase. And we'd also have to decide what the solution would be.

@josevalim
Copy link
Member

Unfortunately I don't think there is an easy solution to this problem. Even though we have subqueries there is no way to pass bindings from the parent query to the child query and this would take a lot of effort to implement. It is something we would accept if someone puts the effort, but it is not something the Ecto team can help with, as we are time constrained.

@jjl
Copy link
Author

jjl commented Apr 17, 2020

The new as and parent_as facilities in ecto master seem to be working out pretty well, so I'm inclined to consider this fixed.

Thanks Jose!

@jjl jjl closed this as completed Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants