Skip to content

Commit 5f35474

Browse files
committed
Respect path_column
1 parent 2fdb539 commit 5f35474

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/hierarch.ex

+6-6
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ defmodule Hierarch do
172172

173173
from(
174174
t in unquote(table),
175-
where: fragment("path = ?", ^roots_path)
175+
where: field(t, ^unquote(path_column)) == ^roots_path
176176
)
177177
end
178178

@@ -187,17 +187,17 @@ defmodule Hierarch do
187187
Build child of a node
188188
"""
189189
def build_child_of(schema, attrs \\ %{})
190-
def build_child_of(schema = %{unquote(:"#{path_column}") => path, __struct__: __MODULE__}, attrs) do
190+
def build_child_of(schema = unquote(schema_argument), attrs) do
191191
{_, id} = get_primary_key(schema)
192192

193193
path = LTree.concat(path, to_string(id))
194-
node_attrs = Map.put(attrs, :path, path)
195-
struct(__MODULE__, node_attrs)
194+
schema_attrs = Map.put(attrs, unquote(path_column), path)
195+
struct(__MODULE__, schema_attrs)
196196
end
197197
# Build the root
198198
def build_child_of(_, attrs) do
199-
node_attrs = Map.put(attrs, :path, "")
200-
struct(__MODULE__, node_attrs)
199+
schema_attrs = Map.put(attrs, unquote(path_column), "")
200+
struct(__MODULE__, schema_attrs)
201201
end
202202

203203
defp blank_query do

0 commit comments

Comments
 (0)