我想使用 Laravel Eloquent 模型和关系来连接我项目中所有表的数据;但是,我在翻译这些关系时遇到了问题。例如,我有两张桌子;第一个是 Books 表,另一个是 Author 表。
Schema::create('books', function (Blueprint $table) {
$table->increments('id');
$table->string('code', 20)->unique('ak_books__code')->nullable(false);
$table->smallInteger('books_type_id');
$table->float('detection_limit', 10, 0);
$table->smallInteger('books_classification_id');
$table->smallInteger('books_number');
$table->foreign(['books_classification_id', 'books_number'], 'fk_books__classification_scales')
->references(['calibration_id', 'number'])->on('classification')
->onUpdate('RESTRICT')->onDelete('RESTRICT');
});
Schema::create('classification', function (Blueprint $table) {
$table->smallInteger('calibration_id');
$table->smallInteger('number');
$table->string('name', 50);
$table->primary(['calibration_id', 'number'], 'pk_classification_scales');
$table->foreign('calibration_id', 'fk_classification_calibration')->references('id')
->on('calibration_parameters')->onUpdate('CASCADE')->onDelete('CASCADE');
});
如何在 Books 表上建立关系以获取number
and calibration_id
?