注意:未定义的索引:joinColumns doctrine 2 + symfony 2 [英] Notice: Undefined index: joinColumns doctrine 2 + symfony 2

查看:125
本文介绍了注意:未定义的索引:joinColumns doctrine 2 + symfony 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有以下实体的结构。
SocieteDiffuseur是指公司Difuser,支付意味着国家和Prix意味着价格。

  class SocieteDiffuseur extends Societe 
{

/ **
* @ ORM\ManyToMany(targetEntity =MG\UtilityBundle\Entity\Pays,inversedBy =societeDiffuseur)
* @ ORM\JoinColumn(nullable = false,name =pays_de_diffusion)
* /
protected $ paysDiffs;

国家:

 code> class Pays 
{
/ **
*
* @ ORM\ManyToMany(targetEntity =MG\UserBundle\Entity\SocieteDiffuseur mappedBy =paysDiffs)
* /
private $ societeDiffuseur;

价格:

 code> 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;

好的,现在我想要的价格(prix)与公司的国家(支付)相同(socetediffuseur)。



所以在我的控制器我在想我必须做的:

 code> $ paysDiffs = $ societe-> getpaysDiffs(); 
$ prix = $ em-> getRepository('MGVenteBundle:Prix') - > findByPays($ paysDiffs);
dump($ prix);出口;

我收到此错误:注意:未定义的索引:joinColumns。



那么我该怎么办?

解决方案

$ societe-> getpaysDiffs (); 返回数组。 findByPays()需要一个类型为Pays而不是数组的参数。



您需要的是编写自定义查询以获得您想要的Prix-es。有关如何执行此操作的更多信息,请参阅此处: http:// symfony.com/doc/current/book/doctrine.html#querying-for-objects


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

这篇关于注意:未定义的索引:joinColumns doctrine 2 + symfony 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆