Skip to content

Commit

Permalink
junction table now has the schema of the first referenced table
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanderhoof committed Nov 20, 2022
1 parent 198fcdf commit 8685a10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions pydbml/classes/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/test_classes/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,17 @@ 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,
"authors_name" varchar NOT NULL,
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:
Expand Down

0 comments on commit 8685a10

Please sign in to comment.