refactor: self relationship

* Add test for self relationship in view
This commit is contained in:
steve-chavez
2022-05-09 21:31:19 -05:00
committed by Steve Chavez
parent c60380b5fc
commit 2be63b36d6
7 changed files with 74 additions and 30 deletions
+1 -4
View File
@@ -5,7 +5,6 @@ module PostgREST.DbStructure.Relationship
( Cardinality(..)
, Relationship(..)
, Junction(..)
, isSelfReference
, RelationshipsMap
) where
@@ -22,6 +21,7 @@ import Protolude
data Relationship = Relationship
{ relTable :: QualifiedIdentifier
, relForeignTable :: QualifiedIdentifier
, relIsSelf :: Bool -- ^ Whether is a self relationship
, relCardinality :: Cardinality
}
deriving (Eq, Ord, Generic, JSON.ToJSON)
@@ -50,8 +50,5 @@ data Junction = Junction
}
deriving (Eq, Ord, Generic, JSON.ToJSON)
isSelfReference :: Relationship -> Bool
isSelfReference r = relTable r == relForeignTable r
-- | Key based on the source table and the foreign table schema
type RelationshipsMap = M.HashMap (QualifiedIdentifier, Schema) [Relationship]