Laravel 4 wiele do wielu relacji nie działa, nie znaleziono tabeli przestawnej
Obecnie mam problemy z relacją n: n z Laravel 4, mam błąd z tabelą przestawną, która jest odpytywana w tabeli z obydwoma komponentami na pojedynczej nazwie. Tworzę tabelę przestawną lands_objs i zapełniam ją:
Modele to:
<?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');
}
}
Oto, jak zapełniam tabelę przestawną zgodnie ze standardami. Oczywiście istnieją tabele lands, objs i 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');
});
}
}
Dzięki tej strukturze powinienem być w stanie zrobić to dzięki Eloquent:
$land = Land::find(1); //checked loads land fine
$objs = $land->objs; //--> HERE I TAKE THE ERROR
Ale popełniam błąd:
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, ))
Czy Laravel nie powinien tworzyć tabeli lands_objs pomimo pytania o land_obj? Czy czegoś mi brakuje?
Wielkie dzięki.