entity-framework - 找不到字段的映射

我要实体

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

最佳答案

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

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

https://stackoverflow.com/questions/14222550/

相关文章:

git - 无法将提交推送到 fork 的 repo

sql - 如何使用带有文本 "|"的 sql 脚本创建文本文件

python - 如何使用 GitPython 指定 Commit 的 committed_date

regex - Clojure 正则表达式匹配

list - Scala 列表中的对象类型

apache - 从 XAMPP 运行 apache 服务时出错

haskell - 与 GADT 的模式匹配

php - 具有任意数量 URL 段的 Laravel 4 路由

c# - 正则表达式检查字符串的第二个字母

perl - 调用 ref 没有返回任何东西