Neo4j-PHP-OGM
Neo4j-PHP-OGM copied to clipboard
The many to many relation are not fetched
I have setup a model MedicalIssue with
_```
/** * @OGM\ManyToMany(relation="medicalIssue") */ protected $symptoms;
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?
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