Doctrine选择一对一双向

时间:2015-03-18 11:51:30

标签: php symfony doctrine-orm

我有这两个类:

Class Account {

/* @var customer
     *
     * @ORM\OneToOne(targetEntity="Customer", inversedBy="account")
     * @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
     */
    private $customer;
}

Class Customer{

/**
     * @var account
     *
     * @ORM\OneToOne(targetEntity="Account", mappedBy="customer")
     */
    private $account;

}

一个查询:

$query = $this->_em->createQuery('SELECT c FROM SbCoreBundle:Customer c LEFT JOIN c.account a WHERE a.id = :user_id');
$query->setParameter('user_id', $id);
return $query->getOneOrNullResult();

我的关系和查询有什么问题?我收到错误:

Column not found: 1054 Unknown column 'c0_.account_id' in 'field list'","errors":null}

1 个答案:

答案 0 :(得分:0)

您是否更新/创建了数据库?

php app / console doctrine:schema:update --force

数据库中是否有字段account_id?