Laravel 4 muitos para muitos relacionamento não está funcionando, tabela dinâmica não encontrada
Atualmente estou tendo problemas com um relacionamento n: n com o Laravel 4, estou tendo um erro com a tabela dinâmica que está consultando em uma tabela com ambos os componentes no nome singular. Eu crio uma tabela dinâmica lands_objs e preencho:
Modelos são:
<?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');
}
}
Aqui está como eu preenchei a tabela dinâmica seguindo os padrões. Claro que as tabelas lands, objs e lands_objs existem:
<?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');
});
}
}
Com essa estrutura eu deveria poder fazer graças ao Eloquent:
$land = Land::find(1); //checked loads land fine
$objs = $land->objs; //--> HERE I TAKE THE ERROR
Mas eu tomo o erro:
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, ))
O Laravel não deveria criar a tabela lands_objs apesar de ter feito uma consulta no land_obj? Estou esquecendo de algo?
Muito obrigado.