コード例 #1
0
    def test_create_sql_with_foreign_key_constraint(self):
        table = Table("users")
        table.add_column("id", "integer")
        table.add_column("profile_id", "integer")
        table.add_column("comment_id", "integer")
        table.add_foreign_key("profile_id", "profiles", "id")
        table.add_foreign_key("comment_id", "comments", "id")
        table.set_primary_key("id")

        sql = (
            'CREATE TABLE "users" ('
            '"id" INTEGER NOT NULL, "profile_id" INTEGER NOT NULL, "comment_id" INTEGER NOT NULL, '
            'CONSTRAINT users_profile_id_foreign FOREIGN KEY ("profile_id") REFERENCES "profiles"("id"), '
            'CONSTRAINT users_comment_id_foreign FOREIGN KEY ("comment_id") REFERENCES "comments"("id"))'
        )

        self.platform.constraintize(table.get_added_constraints())
        self.assertEqual(self.platform.compile_create_sql(table), [sql])
コード例 #2
0
ファイル: test_table.py プロジェクト: circulon/orm
    def test_create_sql_with_foreign_key_constraint(self):
        table = Table("users")
        table.add_column("id", "integer")
        table.add_column("profile_id", "integer")
        table.add_column("comment_id", "integer")
        table.add_foreign_key("profile_id", "profiles", "id")
        table.add_foreign_key("comment_id", "comments", "id")
        table.set_primary_key("id")

        sql = (
            'CREATE TABLE "users" ('
            "id INTEGER PRIMARY KEY, profile_id INTEGER, comment_id INTEGER, "
            "CONSTRAINT users_profile_id_foreign FOREIGN KEY (profile_id) REFERENCES profiles(id), "
            "CONSTRAINT users_comment_id_foreign FOREIGN KEY (comment_id) REFERENCES comments(id))"
        )

        self.platform.constraintize(table.get_added_constraints())
        self.assertEqual(self.platform.compile_create_sql(table), sql)