Skip to content

Commit

Permalink
Allow nullable types (optional list/set) to define one-to-many relations
Browse files Browse the repository at this point in the history
  • Loading branch information
hunyadi committed Nov 19, 2024
1 parent fa678f8 commit 256ec9e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pysqlsync/formation/py_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
is_generic_set,
is_type_enum,
is_type_literal,
is_type_optional,
is_type_union,
unwrap_annotated_type,
unwrap_generic_list,
unwrap_generic_set,
unwrap_literal_types,
unwrap_literal_values,
unwrap_optional_type,
unwrap_union_types,
)
from strong_typing.topological import type_topological_sort
Expand Down Expand Up @@ -497,6 +499,9 @@ def _get_relationship(
:returns: A tuple of host relationship type (e.g. list) and host field type.
"""

if is_type_optional(field_type):
return self._get_relationship(unwrap_optional_type(field_type))

field_type = unwrap_annotated_type(field_type)

# relations must be one-to-many
Expand Down

0 comments on commit 256ec9e

Please sign in to comment.