diff --git a/pgsync/constants.py b/pgsync/constants.py index 3ea19862..9cf95728 100644 --- a/pgsync/constants.py +++ b/pgsync/constants.py @@ -38,6 +38,7 @@ "through_tables", "type", "variant", + "primary_key", ] # Relationship foreign keys diff --git a/pgsync/node.py b/pgsync/node.py index cf726aba..9d11eee1 100644 --- a/pgsync/node.py +++ b/pgsync/node.py @@ -64,6 +64,7 @@ def __post_init__(self): self.through_tables: List[str] = self.relationship.get( "through_tables", [] ) + self.primary_key: List[str] = self.relationship.get("primary_key", []) self.through_nodes: List[Node] = [] if not set(self.relationship.keys()).issubset( @@ -97,7 +98,7 @@ def __post_init__(self): def __str__(self): return ( - f"relationship: {self.variant}.{self.type}:{self.through_tables}" + f"relationship: {self.variant}.{self.type}:{self.through_tables}.{self.primary_key}" ) @@ -149,7 +150,7 @@ def __post_init__(self): table=through_table, schema=self.schema, parent=self, - primary_key=[], + primary_key=self.relationship.primary_key, ) ) @@ -288,8 +289,6 @@ def build(self, data: dict) -> Node: ) self.tables.add(node.table) - for through_node in node.relationship.through_nodes: - self.tables.add(through_node.table) for child in data.get("children", []): node.add_child(self.build(child))