Skip to content

Commit ac34c30

Browse files
authored
fix: don't generate refs for embedded schemas (#50)
1 parent 851acdf commit ac34c30

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

lib/ecto/erd/document/dbml.ex

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,37 @@ defmodule Ecto.ERD.Document.DBML do
5050
end)
5151

5252
refs =
53-
Enum.map_join(edges, "\n", fn %Edge{
54-
from: {from_source, _from_schema, {:field, from_field}},
55-
to: {to_source, _to_schema, {:field, to_field}},
56-
assoc_types: assoc_types
57-
} ->
58-
operator =
59-
if {:has, :one} in assoc_types do
60-
"-"
61-
else
62-
"<"
63-
end
64-
65-
[
66-
"Ref:",
67-
Render.in_quotes(from_source) <> "." <> Render.in_quotes(from_field),
68-
operator,
69-
Render.in_quotes(to_source) <> "." <> Render.in_quotes(to_field)
70-
]
71-
|> Enum.join(" ")
72-
end)
53+
edges
54+
|> Enum.map(&render_edge/1)
55+
|> Enum.reject(&is_nil/1)
56+
|> Enum.join("\n")
7357

7458
groups <> "\n" <> enums <> "\n" <> tables <> "\n" <> refs
7559
end
7660

61+
defp render_edge(%Edge{to: {nil, _, _}}), do: nil
62+
63+
defp render_edge(%Edge{
64+
from: {from_source, _from_schema, {:field, from_field}},
65+
to: {to_source, _to_schema, {:field, to_field}},
66+
assoc_types: assoc_types
67+
}) do
68+
operator =
69+
if {:has, :one} in assoc_types do
70+
"-"
71+
else
72+
"<"
73+
end
74+
75+
[
76+
"Ref:",
77+
Render.in_quotes(from_source) <> "." <> Render.in_quotes(from_field),
78+
operator,
79+
Render.in_quotes(to_source) <> "." <> Render.in_quotes(to_field)
80+
]
81+
|> Enum.join(" ")
82+
end
83+
7784
# tries to cut name from #source_#field format to just #field
7885
@doc false
7986
def enums_mapping(nodes) do

0 commit comments

Comments
 (0)