lphuberdeau / Neo4j-PHP-OGM

A doctrine2 style library to access neo4j graphs
156 stars 45 forks source link

The many to many relation are not fetched #110

Open petrosd7 opened 7 years ago

petrosd7 commented 7 years ago

I have setup a model MedicalIssue with

_```

/**

function __construct(DoctorPatient $doctorPatient = null) { $this->symptoms = new ArrayCollection();

    if ($doctorPatient !== null) {
        $this->setDoctorPatient($doctorPatient);
    }
}

    /**
 * Gets the value of symptoms.
 *
 * @return mixed
 */
public function getSymptoms()
{
    return $this->symptoms;
}

/**
 * Sets the value of symptoms.
 *
 * @param ArrayCollection $symptoms the symptoms
 *
 * @return self
 */
public function setSymptoms(ArrayCollection $symptoms)
{
    $this->symptoms = $symptoms;

    return $this;
}

/**
 * Sets the value of symptoms.
 *
 * @param Symptom $symptom the symptom
 *
 * @return self
 */
public function addSymptom(Symptom $symptom)
{
    $this->symptoms->add($symptom);

    return $this;
}
And the other model Symptom with 
    /**
     *
     * OGM\ManyToOne(relation="medicalIssue")
     */
    protected $medical_issue;

    /**
     * Gets the OGM\ManyToOne(relation="medicalIssue").
     *
     * @return mixed;
     */
    public function getMedicalIssue()
    {
        return $this->medical_issue;
    }

    /**
     * Sets the OGM\ManyToOne(relation="medicalIssue").
     *
     * @param \common\models\MedicalIssue $medical_issue the medical issue
     *
     * @return self
     */
    public function setMedicalIssue(MedicalIssue $medical_issue)
    {
        $this->medical_issue = $medical_issue;

        return $this;
    }

Two problems here
1. When calling 

$issue->addSymptom($symptom); $em->persist($issue); $em->persist($syptom); $em-flush() it is saved succesfully but when $symptom->setMedicalIssue($symptom) $em->persist($issue); $em->persist($syptom); $em-flush()


The relations is not saving

2. I have checked that the relaltion exists in db

but when calling to the existing medical issue getSymptoms() is always empty

$medicalIssue->findOneBy(['id' => $id]);
$medicalIssue->getSymptoms();

Is there any wrong definition?
lphuberdeau commented 7 years ago

You likely need to set the direction on one of those relations in order to say which way the relationship must be read. See https://github.com/lphuberdeau/Neo4j-PHP-OGM/blob/master/lib/HireVoice/Neo4j/Annotation/ManyToMany.php