0

having a defined hyperMorph method in my model and some polymorphic relationships in my Neo4j DB, I've tried these two lines for checking the existence of relationship but both return true , even when there is no a relation between the three nodes:

$e=$parent->function($related)->edge($hyper)->exists();

and

$e=$parent->function($related)->getEdge($hyper)->exists();

where is the problem with these two?

Omid
  • 41
  • 5

1 Answers1

0

The getEdge($hyper) method that you're calling, constructs the relationship with the given models and returns it, with exists it will check if both sides of the relationship exist and whether they do exist in the database (the models not a relationship between them), hence it is always giving you that the relationship exists since you constructed it with getEdge.

In order to work with queries that has to do with fetching records only when a relationship exist, use has and whereHas.

https://laravel.com/docs/5.2/eloquent-relationships#querying-relations under Querying Relationship Existence.

mulkave
  • 831
  • 1
  • 10
  • 22