diff --git a/pydbml/classes/reference.py b/pydbml/classes/reference.py index af82568..f093016 100644 --- a/pydbml/classes/reference.py +++ b/pydbml/classes/reference.py @@ -65,6 +65,7 @@ def join_table(self) -> Optional['Table']: return Table( name=f'{self.table1.name}_{self.table2.name}', + schema=self.table1.schema, columns=( Column(name=f'{c.table.name}_{c.name}', type=c.type, not_null=True, pk=True) # type: ignore for c in chain(self.col1, self.col2) diff --git a/test/test_classes/test_reference.py b/test/test_classes/test_reference.py index 7414a1e..d00e698 100644 --- a/test/test_classes/test_reference.py +++ b/test/test_classes/test_reference.py @@ -181,7 +181,7 @@ def test_many_to_many_sql_composite_different_schemas(self) -> None: ref = Reference('<>', [c11, c12], [c21, c22]) expected = \ -'''CREATE TABLE "books_authors" ( +'''CREATE TABLE "schema1"."books_authors" ( "books_id" integer NOT NULL, "books_author" varchar NOT NULL, "authors_id" integer NOT NULL, @@ -189,9 +189,9 @@ def test_many_to_many_sql_composite_different_schemas(self) -> None: PRIMARY KEY ("books_id", "books_author", "authors_id", "authors_name") ); -ALTER TABLE "books_authors" ADD FOREIGN KEY ("books_id", "books_author") REFERENCES "schema1"."books" ("id", "author"); +ALTER TABLE "schema1"."books_authors" ADD FOREIGN KEY ("books_id", "books_author") REFERENCES "schema1"."books" ("id", "author"); -ALTER TABLE "books_authors" ADD FOREIGN KEY ("authors_id", "authors_name") REFERENCES "schema2"."authors" ("id", "name");''' +ALTER TABLE "schema1"."books_authors" ADD FOREIGN KEY ("authors_id", "authors_name") REFERENCES "schema2"."authors" ("id", "name");''' self.assertEqual(expected, ref.sql) def test_join_table(self) -> None: