Skip to content

Commit

Permalink
Added is_relation property for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
vdboor committed Aug 1, 2024
1 parent 7488419 commit 54eb65e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/schematools/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ def additional_relations(self) -> list[AdditionalRelationSchema]:

def get_reverse_relation(self, field: DatasetFieldSchema) -> AdditionalRelationSchema | None:
"""Find the description of a reverse relation for a field."""
if not field.relation and not field.nm_relation:
if not field.is_relation:
raise ValueError("Field is not a relation")

for relation in self.additional_relations:
Expand Down Expand Up @@ -1473,6 +1473,13 @@ def is_internal(self) -> bool:
"""Id fields for table with composite key is only for internal (Django) use."""
return self.is_primary and self._parent_table.has_composite_key

@cached_property
def is_relation(self) -> bool:
"""Tell whether the field is a relation.
This is a convenience for ``bool(field.relation or field.nm_relation)``.
"""
return bool(self.get("relation"))

@cached_property
def relation(self) -> str | None:
"""Give the 1:N relation, if it exists."""
Expand Down

0 comments on commit 54eb65e

Please sign in to comment.