尝试在DB中查找记录时未定义的索引Doctrine错误

时间:2014-10-29 15:50:06

标签: symfony doctrine find

我尝试从DB获取行但是这段代码:

$company = $this->getDoctrine()->getRepository('AcmeCompanyBundle:Company')->find($company_id);

返回此错误:

Notice: Undefined index: company in /var/www/ontheway/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2714

这是我在github上的公司实体: github

1 个答案:

答案 0 :(得分:2)

/**
 * @ORM\OneToOne(targetEntity="\Vputi\UserBundle\Entity\User", inversedBy="company", cascade={"persist"})
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
private $user;

/**
 * @ORM\OneToMany(targetEntity="Certificate", mappedBy="company", cascade={"persist"})
 */
private $certificates;

你有这两个:

targetEntity="\Vputi\UserBundle\Entity\User", inversedBy="company"
targetEntity="Certificate", mappedBy="company"

我怀疑UserCertificate实体具有company字段。他们呢?