Pierre Dusquel Pierre Dusquel - 8 months ago 32
PHP Question

neo4j ogm returns not all relationships

This is my omg class :

* @OGM\Node(label="Personne")
class Personne
* @OGM\GraphId()
protected $id;

* @OGM\Property(type="string")
protected $nom;

* @OGM\Relationship(targetEntity="Personne", type="SUIT", direction="OUTGOING")
protected $amis;

And I use this code :

$marc = $this->em->getRepository(Personne::class)->findOneBy('nom', 'marc');


But it returns only 1 relationship, not all, what is wrong ?


It is returning only one related "Personne" because you didn't defined the amis properties as a collection in the mapping :

Add collection=true in the @OGM\Relationship annotation.

NB: In PHP 7.1, typed properties can make it in, a future version of the OGM might take advantage of it (meaning then that this version would be 7.1+ only)

Actually I think the OGM should throw an exception in case there is more than one relationship found.