Laravel 4 отношения многие ко многим не работают, сводная таблица не найдена
В настоящее время у меня проблемы с отношением n: n с Laravel 4, у меня ошибка с сводной таблицей, которая запрашивает таблицу с обоими компонентами с единичным именем. Я создаю сводную таблицу lands_objs и заполняю ее:
Модели:
<?php
class Obj extends Eloquent
{
protected $guarded = array();
public static $rules = array();
public $timestamps = false;
public function land()
{
return $this->belongsToMany('Land');
}
<?php
class Land extends Eloquent
{
protected $guarded = array();
public static $rules = array();
public $timestamps = false;
public function objs()
{
return $this->belongsToMany('Obj');
}
}
Вот как я заполняю сводную таблицу, следуя стандартам. Конечно, существуют таблицы lands, objs и lands_objs:
<?php
use Illuminate\Database\Migrations\Migration;
class CreateLandsObjsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('lands_objs', function($table) {
$table->integer('land_id');
$table->integer('obj_id');
});
}
}
С этой структурой я должен быть в состоянии сделать благодаря Eloquent:
$land = Land::find(1); //checked loads land fine
$objs = $land->objs; //--> HERE I TAKE THE ERROR
Но я принимаю ошибку:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'taylor.land_obj' doesn't exist
(SQL: select `objs`.*, `land_obj`.`land_id` as `pivot_land_id`, `land_obj`.`obj_id`
as `pivot_obj_id` from `objs` inner join `land_obj` on `objs`.`id` = `land_obj`.`obj_id`
where `land_obj`.`land_id` = ?) (Bindings: array ( 0 => 1, ))
Разве Laravel не должен создавать таблицу lands_objs, несмотря на запросы на land_obj? Я что-то пропустил?
Большое спасибо.