Skip to content

Support lateral join subqueries #3272

@jjl

Description

@jjl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions