Laravel 4 viele zu viele Beziehung nicht funktioniert, pivot-Tabelle nicht gefunden

Bin ich derzeit Probleme mit einem n:n-Beziehung mit Laravel 4, ich habe einen Fehler mit der pivot-Tabelle, die quering auf einem Tisch mit beiden Komponenten auf einzelne Namen. Ich erstelle eine pivot-Tabelle lands_objs und füllen Sie es:

Modelle sind:

<?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');
        }
     }

Hier ist, wie ich das Auffüllen der pivot-Tabelle nach den standards. Natürlich landet, objs und lands_objs Tabellen existieren:

<?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');
        });
    }
}

Mit dieser Struktur, ich sollte in der Lage sein zu tun, Dank Beredt:

$land = Land::find(1);  //checked loads land fine
$objs = $land->objs; //--> HERE I TAKE THE ERROR

Nehme ich aber den Fehler:

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, ))

Sollte nicht Laravel erstellen der Tabelle lands_objs trotz quering auf land_obj? Bin ich etwas fehlt?

Vielen Dank.

InformationsquelleAutor Joss | 2013-05-05
Schreibe einen Kommentar