【问题标题】:Laravel NeoEloquent - Dynamic relations between same node classLaravel NeoEloquent - 同一节点类之间的动态关系
【发布时间】:2016-10-03 10:37:51
【问题描述】:
【问题讨论】:
标签:
laravel
neo4j
neoeloquent
【解决方案1】:
我通过使用多态关系来修复它。这不是最佳选择,因为使用我想在关系上设置的属性创建了一个额外的节点,但它目前有效。这是我创建的关系类:
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');
}
}
这是 Term 类:
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