In the method below, we check if foreign key refers to unique constraint of target table and if so the cardinality is going to be ONE_TO_ZERO_OR_ONE or ONE_TO_EXACTLY_ONE.
But foreign key can refer to the column/columns that belongs to the Primary key, in this case it should be ONE_TO_ZERO_OR_ONE or ONE_TO_EXACTLY_ONE too, but in our case it is not taken into account and this cases are going into _TO_MANY.
@cached_property
def _is_ref_to_unique(self) -> bool:
"""
Check if the referenced foreign key refers to unique constraint of target table
"""
ref_fk_columns = {dsf.name for dsf in self.ref_fk_field_list}
ref_uc_columns = list(
chain.from_iterable(uc.column_names for uc in self.unique_constraints)
)
return any(cn in ref_uc_columns for cn in ref_fk_columns)
In the method below, we check if foreign key refers to unique constraint of target table and if so the cardinality is going to be
ONE_TO_ZERO_OR_ONE
orONE_TO_EXACTLY_ONE
. But foreign key can refer to the column/columns that belongs to the Primary key, in this case it should beONE_TO_ZERO_OR_ONE
orONE_TO_EXACTLY_ONE
too, but in our case it is not taken into account and this cases are going into _TO_MANY.