@@ -50,30 +50,37 @@ defmodule Ecto.ERD.Document.DBML do
50
50
end )
51
51
52
52
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 " )
73
57
74
58
groups <> "\n " <> enums <> "\n " <> tables <> "\n " <> refs
75
59
end
76
60
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
+
77
84
# tries to cut name from #source_#field format to just #field
78
85
@ doc false
79
86
def enums_mapping ( nodes ) do
0 commit comments