2013-06-19 154 views
0

我需要在实体2,实体1和类型之间创建多态关系。 事件和类型之间的关系很容易做到,但是在Entity2和Types之间的关系中存在一个问题,因为它是一个多对多的关系。多对多多态关系

enter image description here

class CreateTypesTable extends Migration { 
    public function up() 
    { 
     Schema::create('types', function(Blueprint $table) { 
      $table->increments('id'); 
      $table->integer('typeable_id'); 
      $table->string('typeable_type', 20); 
      $table->string('name', 20); 
      $table->text('description')->nullable(); 
     }); 
    } 
} 

class Entity1 extends Eloquent { 
    public function type() 
    { 
     return $this->morphMany('App\Models\Type', 'typeable'); 
    } 
} 

class Type extends Eloquent { 

    public function typeable() 
    { 
     return $this->morphTo(); 
    } 
} 

的类型和Entitys2之间的关系是多对多的,不知道如何创建,因为它需要一个数据透视表。

class Entity2 extends Eloquent { 
     public function types() 
     { 
//   return $this->morphMany('App\Models\Type', 'typeable'); 
     } 
    } 

回答