0
我有2個實體與許多連接到許多關係到3TH表,我想每一個顏色產品的ID:Symfony的 - 建立了許多創建的表查詢到很多關係
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Color", inversedBy="products")
* @ORM\JoinTable(name="products_colors",
* joinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="color_id", referencedColumnName="id")}
* )
*/
private $colors;
而在我的第二個實體:
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Product", mappedBy="colors")
*/
private $products;
這是我的查詢:(我試圖讓一些連接,但不能使它工作)
class ProductRepository extends \Doctrine\ORM\EntityRepository
{
public function getColors($id)
{
$query = $this->createQueryBuilder('p')
->join('AppBundle\Entity\Color', 'c')
->where('c.product_id = :id')
->setParameter('id', $id)
->getQuery()
->getResult();
return $query;
}
}
我得到這個錯誤:
[Semantical Error] line 0, col 85 near 'product_id =': Error: Class AppBundle\Entity\Color has no field or association named product_id
我明白,但想不到一種方法來使這項工作。
Omg,即時通訊如此愚蠢,我已經做到了這一點,我做了之前,並有getColors函數,而不是使用它,即時通訊嘗試建立一些黑魔法:O謝謝 –