我通过使用多态关系来修复它。这不是最优的,因为使用我想在关系上设置的属性创建了一个额外的节点,但它目前有效。这是我创建的关系类:
class Relation extends NeoEloquent
{
protected $label = 'Relation';
protected $guarded = [];
public $timestamps = false;
protected $fillable = ['relation_name','relation_description'];
public function subject()
{
return $this->morphMany('App\Term','TO');
}
}
这是术语类:
class Term extends NeoEloquent
{
protected $label = 'Term';
protected $guarded = [];
public $timestamps = false;
protected $fillable = ['term_name','term_definition'];
public function author()
{
return $this->belongsTo('App\User', 'CREATED');
}
public function relationship($morph=null)
{
return $this->hyperMorph($morph, 'App\Relation', 'RELATION', 'TO');
}
public function object()
{
return $this->belongsToMany('App\Term', 'RELATION');
}
public function whichRelation()
{
return $this->morphMany('App\Relation','TO');
}
}
我将一些部分开源为 Laravel + NeoEloquent + Neo4j 演示。github的链接在这里:https ://github.com/pietheinstrengholt/laravel-neo4j-neoeloquent-demo