Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
633 stars 199 forks source link

Relations have wrong direction #227

Closed emredoganm closed 7 years ago

emredoganm commented 7 years ago

In my Categories model, I declared relationships like this:

    public function children(){
      return $this->hasMany("Models\Categories", "IS_CHILD_OF");
    }

    public function parent(){
      return $this->belongsTo("Models\Categories", "IS_CHILD_OF");
    }

but when I run this:

    $programming = Categories::whereName("programming")->first();
    $neo4j = $programming->children()->save(Categories::create([
        "name" => "neo4j"
   ]));

relationship direction has wrong direction. image

emredoganm commented 7 years ago

Also Category::has('children')->get() or Category::has('parent')->get() queries return empty collections. Maybe this problem related to the problem above... If not I can open a new issue.

KinaneD commented 7 years ago

Hi @emredoganm In your categories model you declared two relationships to the same categories model. Is this intended?

emredoganm commented 7 years ago

Is this un-solicited status? A category may has a parent category and children categories. How can I declare?

Mulkave commented 7 years ago

@emredoganm there doesn't seem to be anything wrong in the sample you posted. hasMany means programming -[IS_CHILD_OF]-> children declared with a hasMany relationship. While programming <-[IS_CHILD_OF]- parent declared with a belongsTo. All as described in the docs https://github.com/vinelab/neoeloquent#one-to-many

Is there anything that you find confusing about this?

emredoganm commented 7 years ago

I think I should change my relation name to "HAS_CHILD". It is more smarter :-D

thanosalexander commented 6 years ago

i have to reopen :smiley: When i use createWith (with parent relationship inside), it is displayed correctly in graph preview. But when i use $model->parent()->associate($parent)->save() direction is displayed as edgeout..