refactor: add isParent flag to O2O relationships

It allows to identify the side with the FK when isParent == False
This commit is contained in:
Laurence Isla
2024-05-21 12:11:27 -05:00
committed by GitHub
parent 04d6f41f45
commit 7671d63f06
5 changed files with 33 additions and 32 deletions
+6 -6
View File
@@ -44,8 +44,8 @@ data Cardinality
-- ^ one-to-many
| M2O {relCons :: FKConstraint, relColumns :: [(FieldName, FieldName)]}
-- ^ many-to-one
| O2O {relCons :: FKConstraint, relColumns :: [(FieldName, FieldName)]}
-- ^ one-to-one, this is a refinement over M2O so operating on it is pretty much the same as M2O
| O2O {relCons :: FKConstraint, relColumns :: [(FieldName, FieldName)], isParent :: Bool}
-- ^ one-to-one, this is a refinement over M2O, operating on it is pretty much the same as M2O when isParent == False
| M2M Junction
-- ^ many-to-many
deriving (Eq, Show, Ord, Generic, JSON.ToJSON)
@@ -67,7 +67,7 @@ type RelationshipsMap = HM.HashMap (QualifiedIdentifier, Schema) [Relationship]
relIsToOne :: Relationship -> Bool
relIsToOne rel = case rel of
Relationship{relCardinality=M2O _ _} -> True
Relationship{relCardinality=O2O _ _} -> True
ComputedRelationship{relToOne=True} -> True
_ -> False
Relationship{relCardinality=M2O {}} -> True
Relationship{relCardinality=O2O {}} -> True
ComputedRelationship{relToOne=True} -> True
_ -> False