我尝试从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
答案 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"
我怀疑User
或Certificate
实体不具有company
字段。他们呢?