Skip to content

The many to many relation are not fetched #110

@petrosd7

Description

@petrosd7

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions