neo4j ogm returns not all relationships

111 Views Asked by At

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');

print_r($marc->getAmis());

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

1

There are 1 best solutions below

0
On BEST ANSWER

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.