【问题标题】:Laravel NeoEloquent - Dynamic relations between same node classLaravel NeoEloquent - 同一节点类之间的动态关系
【发布时间】:2016-10-03 10:37:51
【问题描述】:

我正在使用 Laravel 和 Neo4j 作为后端进行概念验证。 NeoEloquent 是目前的首选:https://github.com/Vinelab/NeoEloquent

目前我有一个与“术语”有很多关系的“人”模型。这很好用,正如它所描述的那样:https://github.com/Vinelab/NeoEloquent#one-to-many

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

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

【问题讨论】:

    标签: 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      相关资源
      最近更新 更多