这是我的实体:
/**
* Productgeneral
* @ORM\Table(name="ProductGeneral", indexes={@ORM\Index(name="category_id", columns={"category_id"})})
* @ORM\Entity
*/
class Productgeneral {
//some cols
/**
* @var integer
*
* @ORM\Column(name="product_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $productId;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Productimg", inversedBy="product")
* @ORM\JoinTable(name="producttoimg",
* joinColumns={
* @ORM\JoinColumn(name="product_id", referencedColumnName="product_id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="img_id", referencedColumnName="img_id")
* }
* )
*/
private $img;
/**
* Constructor
*/
public function __construct() {
$this->img = new \Doctrine\Common\Collections\ArrayCollection();
}
//getter & setters
}
/**
* Productimg
* @ORM\Table(name="ProductImg")
* @ORM\Entity
*/
class Productimg {
/**
* @var integer
*
* @ORM\Column(name="img_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $imgId;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Productgeneral", mappedBy="img")
*/
private $product;
/**
* Constructor
*/
public function __construct() {
$this->product = new \Doctrine\Common\Collections\ArrayCollection();
}
//getters & setters
}
当我跑步时:
*$this->getDoctrine()->getRepository('AppBundle:Productgeneral')->findAll();*
我得到了每一列的正确值,但是img
;它返回一个PersistentCollection
而不是所有图像的数组。
难道我做错了什么?或者我只是误解了这段关系的行为?
默认的 Doctrine 行为是延迟获取映射实体,因此当您转储实体时,它看起来为空,因为数据尚未加载。
如果您调用 getImg 方法,则原则将查询您的数据库以加载链接到您的产品的相关 Productimg 实体。
一旦 ArrayCollection 被实体管理器持久化和管理,它就成为 PersistentCollection,它的行为与 ArrayCollection 完全相同
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)