Skip to content

Commit 48b2703

Browse files
committed
fix: don't attempt to use non-existent relationship
1 parent 25fbdfc commit 48b2703

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

lib/resource_generator/resource_generator.ex

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,26 @@ defmodule AshPostgres.ResourceGenerator do
362362
Enum.find(table_spec.relationships, fn relationship ->
363363
relationship.type == :belongs_to and
364364
relationship.constraint_name == foreign_key.constraint_name
365-
end).name
366-
367-
options =
368-
""
369-
|> add_on(:update, foreign_key.on_update)
370-
|> add_on(:delete, foreign_key.on_delete)
371-
|> add_match_with(foreign_key.match_with)
372-
|> add_match_type(foreign_key.match_type)
373-
374-
[
375-
"""
376-
reference :#{relationship} do
377-
#{options}
378-
end
379-
"""
380-
]
365+
end)
366+
367+
if relationship do
368+
relationship = relationship.name
369+
370+
options =
371+
""
372+
|> add_on(:update, foreign_key.on_update)
373+
|> add_on(:delete, foreign_key.on_delete)
374+
|> add_match_with(foreign_key.match_with)
375+
|> add_match_type(foreign_key.match_type)
376+
377+
[
378+
"""
379+
reference :#{relationship} do
380+
#{options}
381+
end
382+
"""
383+
]
384+
end
381385
end
382386
|> Enum.join("\n")
383387
|> String.trim()

0 commit comments

Comments
 (0)