Skip to content

Commit

Permalink
docs: fix manual cte relationship example
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 9, 2024
1 parent 6da0cf0 commit 4392ee1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions documentation/topics/advanced/manual-relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,18 @@ defmodule MyApp.Employee.ManagedEmployees do
# https://stackoverflow.com/questions/39458572/ecto-declare-schema-for-a-query
employee_keys = Employee.__schema__(:fields)

cte_name =
cte_name_ref =
from(cte in fragment("?", literal(^cte_name)), select: map(cte, ^employee_keys))

recursion_query =
query
|> join(:inner, [l], lt in ^cte_name, on: l.manager_id == lt.id)
|> join(:inner, [l], lt in ^cte_name_ref, on: l.manager_id == lt.id)

descendants_query =
immediate_parents
|> union(^recursion_query)

cte_name
cte_name_ref
|> recursive_ctes(true)
|> with_cte(^cte_name, as: ^descendants_query)
end
Expand Down

0 comments on commit 4392ee1

Please sign in to comment.