第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在二對多關系上使用兩個表或?qū)⑷齻€表與數(shù)據(jù)透視表一起使用

在二對多關系上使用兩個表或?qū)⑷齻€表與數(shù)據(jù)透視表一起使用

PHP
浮云間 2022-05-27 15:02:42
基本上,我的數(shù)據(jù)庫中有 2 個表:Games 和 Teams。每場比賽必須有 2 支球隊,所以這是一個二對多的關系。我應該在我的 Games 表中使用 2 個外鍵指向 Teams 表中的 2 個團隊并具有一對多關系,還是使用與第三個表的多對多關系來鏈接游戲和團隊表?我在項目中使用 Laravel 6.5,所以我猜我使用 Eloquent 來實現(xiàn)它。Schema::create('games', function (Blueprint $table) {            $table->bigIncrements('id');            $table->unsignedBigInteger('team_a_id');            $table->foreign('team_a_id')->references('id')->on('teams')->onDelete('restrict');            $table->unsignedBigInteger('team_b_id');            $table->foreign('team_b_id')->references('id')->on('teams')->onDelete('restrict');            $table->unsignedInteger('team_a_score');            $table->unsignedInteger('team_b_score');            $table->string('status');            $table->boolean('finished');        });Schema::create('teams', function (Blueprint $table) {            $table->bigIncrements('id');            $table->string('name');            $table->string('abbreviation');            $table->string('country');            $table->timestamps();        });這是我現(xiàn)在創(chuàng)建的兩個表,這是實現(xiàn)它的正確方法嗎?
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經(jīng)驗 獲得超5個贊

使用多對多關系。在這種情況下,游戲模式可能有多個團隊,反之亦然。


因此遷移將是這樣的:


  Schema::create('games', function (Blueprint $table) {

        $table->bigIncrements('id');

        $table->string('status');

        $table->boolean('finished');

  });


  Schema::create('teams', function (Blueprint $table) {

        $table->bigIncrements('id');

        $table->string('name');

        $table->string('abbreviation');

        $table->string('country');

        $table->timestamps();

  });


  Schema::create('game_team', function (Blueprint $table) {

        $table->bigIncrements('id');

        $table->integer('game_id');

        $table->integer('team_id');

        $table->unsignedInteger('score');

        $table->timestamps();

  });


查看完整回答
反對 回復 2022-05-27
  • 1 回答
  • 0 關注
  • 162 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號