I have the following structure of Entities in my project. "SocieteDiffuseur" means CompanyDifuser, pays means country and Prix means Price.
class SocieteDiffuseur extends Societe
{
/**
* @ORM\ManyToMany(targetEntity="MG\UtilityBundle\Entity\Pays", inversedBy="societeDiffuseur")
* @ORM\JoinColumn(nullable=false, name="pays_de_diffusion")
*/
protected $paysDiffs;
Country :
class Pays
{
/**
*
* @ORM\ManyToMany(targetEntity="MG\UserBundle\Entity\SocieteDiffuseur", mappedBy="paysDiffs")
*/
private $societeDiffuseur;
Price :
class Prix
{
/**
* @ORM\ManyToMany(targetEntity="MG\UtilityBundle\Entity\Pays")
* @ORM\JoinTable(name="prix_pays",
* joinColumns={@ORM\JoinColumn(name="prix_id", referencedColumnName ="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="pays_id", referencedColumnName="id", unique=false)}
* )
*/
private $pays;
Ok, now i want the Price (prix) who have the same country (pays) than the company (societediffuseur).
So in my controller I was thinking I had to do:
$paysDiffs = $societe->getpaysDiffs();
$prix = $em->getRepository('MGVenteBundle:Prix')->findByPays($paysDiffs);
dump($prix); exit;
And i get this error : Notice: Undefined index: joinColumns.
So what should i do ?
$societe->getpaysDiffs();
returns an array.findByPays()
requires an argument of type Pays, not an array.What you need is to write a custom query to get the Prix-es you want. See here for more information about how to do that: http://symfony.com/doc/current/book/doctrine.html#querying-for-objects