大佬教程收集整理的这篇文章主要介绍了Symfony 多对多返回空的 ArrayCollection,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个实体 Product 和 Part,通过多对多关系连接。
class Part
{
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Product",mappedBy="parts",fetch="EAGER")
*/
private $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getProducts()
{
return $this->products;
}
}
class Product
{
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Part",inversedBy="products",cascade={"persist"})
* @ORM\Jointable(name="products_parts",* joincolumns={
* @ORM\Joincolumn(name="product_ID",referencedcolumnname="ID")
* },* inverseJoincolumns={
* @ORM\Joincolumn(name="part_ID",referencedcolumnname="ID")
* }
* )
*/
private $parts;
public function __construct()
{
$this->parts = new ArrayCollection();
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getParts()
{
return $this->parts;
}
/**
* @param $parts
*/
public function setParts($parts)
{
$this->parts = $parts;
}
}
当我尝试获取单个产品并显示所有相关部件时。 Symfony 返回一个空数组。尽管数据已正确添加到数据库中。我哪里做错了?
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Symfony 多对多返回空的 ArrayCollection全部内容,希望文章能够帮你解决Symfony 多对多返回空的 ArrayCollection所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。