coryodaniel / arbor

Ecto elixir adjacency list and tree traversal. Supports Ecto versions 2 and 3.
MIT License
239 stars 26 forks source link

ancestors error #30

Closed getong closed 4 years ago

getong commented 5 years ago

My table is in other schema, let's say "network", not the public. the ancestors function output:

SELECT u0."id", u0."name", u0."superior_id" FROM "network"."user" AS u0 INNER JOIN (
  WITH RECURSIVE user_tree AS (
    SELECT id,
          superior_id,
          0 AS depth
    FROM user
    WHERE id = 4
  UNION ALL
    SELECT user.id,
          user.superior_id,
          user_tree.depth + 1
    FROM user
      JOIN user_tree
      ON user_tree.superior_id = user.id
  )
  SELECT *
  FROM user_tree
)
 AS f1 ON u0."id" = f1."superior_id"

but the sql should be:

SELECT u0."id", u0."name", u0."superior_id" FROM "network"."user" AS u0 INNER JOIN (
  WITH RECURSIVE user_tree AS (
    SELECT id,
          superior_id,
          0 AS depth
    FROM "network".user
    WHERE id = 4
  UNION ALL
    SELECT id,
          superior_id,
          user_tree.depth + 1
    FROM user
      JOIN user_tree
      ON user_tree.superior_id = id
  )
  SELECT *
  FROM user_tree
)
 AS f1 ON u0."id" = f1."superior_id"

But I don't know how to add the schema name to the table.

coryodaniel commented 4 years ago

This may be related to: https://github.com/coryodaniel/arbor/issues/23

coryodaniel commented 4 years ago

I can't reproduce this, can you make a minimal example in a github that does and share it?