Skip to content

Commit

Permalink
test: Added test for foreign_id_for
Browse files Browse the repository at this point in the history
  • Loading branch information
maicol07 committed Jul 18, 2022
1 parent 11ccf4e commit 1b236af
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/mysql/schema/test_mysql_schema_builder.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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`))"
],
)

Expand Down

0 comments on commit 1b236af

Please sign in to comment.