【发布时间】:2023-03-09 21:40:01
【问题描述】:
我制作这个架构是为了将特定季节的价格保存在特定板中
示例:Hotel X 八月半食宿 50 欧元,全食宿 50 欧元 ...
Schema::create('boards', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->increments('id');
$table->string('name', 45);
});
Schema::create('seasons', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->increments('id');
$table->string('name', 45);
});
Schema::create('hotels', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->increments('id');
$table->string('name', 45);
$table->string('city');
$table->unsignedInteger('agency_id');
$table->foreign('agency_id')->references('id')->on('agencies');
$table->timestamps();
});
Schema::create('hotel_schedules', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->increments('id');
$table->unsignedInteger('hotel_id');
$table->unsignedInteger('board_id');
$table->unsignedInteger('season_id');
$table->decimal('price', 7, 2);
$table->foreign('hotel_id')->references('id')->on('hotels');
$table->foreign('board_id')->references('id')->on('boards');
$table->foreign('season_id')->references('id')->on('seasons');
$table->timestamps();
});
在模型 Boards、Seasons 和 Hotels 之间添加关系的正确方法是什么? 创建另一个模型调用 HotelSchedule 是否正确?
谢谢
【问题讨论】:
-
我认为创建中间表
hotel_schedules是正确的,因为这就是这些表相关的地方。
标签: laravel eloquent relationship