2

我必须实体

class Patients 

    {
         /**
         * @ORM\OneToOne(targetEntity="ContactAddress", mappedBy="patients")
         */
        protected $contactaddress;
    }

还有一个

class ContactAddress
{
    /**
     * @ORM\OneToOne(targetEntity="Patients", inversedBy="contactaddress")
     * @ORM\JoinColumn(name="patient_id", referencedColumnName="id")
     */
     protected $patient;
}

当我尝试执行此代码时

$em = $this->getDoctrine()->getEntityManager();
$product = $em->getRepository('SurgeryPatientBundle:Patients')->find($id);

我明白了

No mapping found for field 'patients' on class 'Surgery\PatientBundle\Entity\ContactAddress'. 

当我尝试访问联系人存储库时,我得到了结果

请帮助;D对不起我的英语

4

1 回答 1

11

您必须在 ContactAddress 实体中引用patient而不是病人*s*。

class Patients 
{
     /**
     * @ORM\OneToOne(targetEntity="ContactAddress", mappedBy="patient")
     */
    protected $contactaddress;
}
于 2013-01-08T19:48:56.710 回答