找不到字段的映射

时间:2013-01-08 19:25:26

标签: entity-framework symfony orm doctrine mapping

我必须要实体

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. 对不起我的英文

1 个答案:

答案 0 :(得分:7)

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

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