Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
636 stars 200 forks source link

Conflict on Same Model #228

Closed emredoganm closed 4 years ago

emredoganm commented 7 years ago

As mentioned in documentation here, I've created a User model and followersrelationship like this:

  public function followers()
  {
    return $this->belongsToMany(User::class, "FOLLOWS");
  }

But when I debug this query:

dd(User::has("followers")->get());

and echoing out $query from run() function in Vinelab\Eloquent\Connection the result is:

MATCH (user:`User`), (user)<-[rel_follows_user:FOLLOWS]-(user:`User`) WITH user, count(user) AS user_count WHERE user_count >= 1 RETURN user

Target node is named as user and source node is named as user and it conflicts in Cypher and returns an empty collection. I think it is a bug. How can we solve this?

emredoganm commented 7 years ago

I have created a PR for this problem: #229.

This PR will generate a cypher query like this with situtation above:

dd(User::has("followers")->get());

Cypher query:

MATCH (user:`User`), (user)<-[rel_follows_user:FOLLOWS]-(related_user:`User`) WITH user, count(related_user) AS user_count WHERE user_count >= 1 RETURN user
Mulkave commented 6 years ago

Please confirm the fix of this in your PR to close.

k98kurz commented 6 years ago

@Mulkave is there some reason his suggested fix was not implemented? It is kind of embarrassing for your example code to not work.

Mulkave commented 6 years ago

@k98kurz this would require further testing and spectating to figure out whether it has any side effects on mapping or hydrating models, since it relies on these variables to figure out the properties.

Not sure if @emredoganm is still up for the fix?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.