From 1b236af5a375dae9e411cb666a2ad88bccbf6776 Mon Sep 17 00:00:00 2001 From: Maicol Battistini Date: Mon, 18 Jul 2022 10:32:14 +0200 Subject: [PATCH] test: Added test for `foreign_id_for` --- tests/mysql/schema/test_mysql_schema_builder.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/mysql/schema/test_mysql_schema_builder.py b/tests/mysql/schema/test_mysql_schema_builder.py index ccf67ebc..f2019e9b 100644 --- a/tests/mysql/schema/test_mysql_schema_builder.py +++ b/tests/mysql/schema/test_mysql_schema_builder.py @@ -1,12 +1,17 @@ import os import unittest +from masoniteorm import Model from tests.integrations.config.database import DATABASES from src.masoniteorm.connections import MySQLConnection from src.masoniteorm.schema import Schema from src.masoniteorm.schema.platforms import MySQLPlatform +class Discussion(Model): + pass + + class TestMySQLSchemaBuilder(unittest.TestCase): maxDiff = None @@ -92,6 +97,7 @@ def test_can_add_columns_with_foreign_key_constaint(self): blueprint.integer("profile_id") blueprint.foreign("profile_id").references("id").on("profiles") blueprint.foreign_id("post_id").references("id").on("posts") + blueprint.foreign_id_for(Discussion).references("id").on("discussions") self.assertEqual(len(blueprint.table.added_columns), 3) self.assertEqual( @@ -103,7 +109,8 @@ def test_can_add_columns_with_foreign_key_constaint(self): "`post_id` BIGINT UNSIGNED NOT NULL, " "CONSTRAINT users_name_unique UNIQUE (name), " "CONSTRAINT users_profile_id_foreign FOREIGN KEY (`profile_id`) REFERENCES `profiles`(`id`), " - "CONSTRAINT users_profile_id_foreign FOREIGN KEY (`post_id`) REFERENCES `posts`(`id`))" + "CONSTRAINT users_profile_id_foreign FOREIGN KEY (`post_id`) REFERENCES `posts`(`id`)), " + "CONSTRAINT users_discussions_id_foreign FOREIGN KEY (`discussion_id`) REFERENCES `posts`(`id`))" ], )