Doctrine 2 ManyToMany保存但不提取

时间:2015-07-03 20:37:47

标签: php symfony doctrine-orm

在我的公司实体类中,这就是我声明地址的方式:

/**
 * The addresses the company has had. The one with the newest create date
 * is the current address.
 *
 * Mapped as many to many with a unique constraint to force the one to
 * many relationship:
 * @ORM\ManyToMany(targetEntity="\AppBundle\Entity\Address", cascade={"persist"})
 * @ORM\JoinTable(name="fp_company_addresses",
 *     joinColumns={@ORM\JoinColumn(name="company_id", referencedColumnName="id")},
 *     inverseJoinColumns={@ORM\JoinColumn(name="address_id", referencedColumnName="id")}
 *     )
 *
 * @var ArrayCollection Collection of addresses
 */
private $addresses;

当我们在公司表单中保存公司详细信息时,地址将保存在数据库中,但是当我们想要获得这样的公司列表时:

$companies = $this->getRepo('AppBundle:Company')->findAll();

我们正在为地址获取一个空数组,即使我们在数据库中有它。

我错过了什么?

0 个答案:

没有答案