2016-10-03 126 views
0

我正在研究使用Laravel和Neo4j作为后端的概念验证。 NeoEloquent现在是被选择的选择:https://github.com/Vinelab/NeoEloquentLaravel NeoEloquent - 同一节点类之间的动态关系

目前,我有一个“人”模型与'term'hasmany关系。这很有效,正如它所描述的:https://github.com/Vinelab/NeoEloquent#one-to-many

下一步是创建动态关系。所以一个术语可以与另一个术语有关系。关系类型也必须灵活。因此,它可以是一种,复制,关系,等等。就像这样:

enter image description here

的关系类型不应该是固定的,并会在稍后阶段进行可视化。什么是最好的方法呢?我可以使用多态关系和HyperEdges来做到这一点吗?从我的理解是,多态关系中创建了一个额外的节点。这个概念与Neo4j的工作方式不同,其中边缘具有属性和属性。我对吗?什么是最好的方法呢?

回答

0

我通过使用Polymorphic关系修复它。这不是最优的,因为使用我想要在关系上设置的属性来创建额外的节点,但它现在起作用。这里是关系类,我创建:

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