2014-11-04 73 views
0

我在一對多連接的兩個連接實體,但是當我試圖讓查詢出來,我收到以下錯誤Symfony2的學說加入一對多不工作

注意:未定義指數:myBox上在/ var/WWW/PP /供應商/教義/ ORM/LIB /學說/ ORM /查詢/ SqlWalker.php線887

我的實體是如下所示: myBox上(一個)

<?php 
namespace Pp\CoreBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Doctrine\Common\Collections\ArrayCollection; 
use Gedmo\Mapping\Annotation as Gedmo; 

/** 
* @ORM\Entity(repositoryClass="Pp\CoreBundle\Repository\MyboxRepository") 
* @ORM\Table(name="Mybox") 
*/ 
class Mybox 
{ 
    public static $collectingTypeAny = 0; 
    public static $collectingTypeFixed = 1; 
    public static $collectingTypeMinimum = 2; 

    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 


    /** 
    * @ORM\ManyToOne(targetEntity="Pp\UserBundle\Entity\User") 
    * @ORM\JoinColumn(name="user_id", referencedColumnName="id") 
    */ 
    protected $user; 

    /** 
    * @ORM\Column(type="integer",nullable=TRUE) 
    */ 
    protected $user_id; 

    /** 
    * @ORM\OneToMany(targetEntity="Pp\CoreBundle\Entity\Mybox", mappedBy="Mybox") 
    */ 
    protected $PaypalPayment; 


    public function __construct(){ 
     // set default value for paypal with an array. 
     $this->PaypalPayment = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 


    /** 
    * Set user 
    * 
    * @param \Pp\UserBundle\Entity\User $user 
    * @return Mybox 
    */ 
    public function setUser(\Pp\UserBundle\Entity\User $user = null) 
    { 
     $this->user = $user; 

     return $this; 
    } 

    /** 
    * Get user 
    * 
    * @return \Pp\UserBundle\Entity\User 
    */ 
    public function getUser() 
    { 
     return $this->user; 
    } 

    /** 
    * Add PaypalPayment 
    * 
    * @param \Pp\CreditBundle\Entity\Mybox $paypalPayment 
    * @return Mybox 
    */ 
    public function addPaypalPayment(\Pp\CreditBundle\Entity\PaypalPayment $paypalPayment) 
    { 
     $this->PaypalPayment[] = $paypalPayment; 

     return $this; 
    } 

    /** 
    * Remove PaypalPayment 
    * 
    * @param \Pp\CreditBundle\Entity\Mybox $paypalPayment 
    */ 
    public function removePaypalPayment(\Pp\CreditBundle\Entity\PaypalPayment $paypalPayment) 
    { 
     $this->PaypalPayment->removeElement($paypalPayment); 
    } 

    /** 
    * Get PaypalPayment 
    * 
    * @return \Doctrine\Common\Collections\Collection 
    */ 
    public function getPaypalPayment() 
    { 
     return $this->PaypalPayment; 
    } 

    /** 
    * get all the payments type in a array 
    * 
    * @return array 
    */ 
    public function getPayments() { 
     $allPayments = Array(); 
     foreach ($this->getPaypalPayment() as $paypalPayment) { 
      $allPayments[] = $paypalPayment; 
     } 
     return $allPayments; 
    } 


    /** 
    * Set user_id 
    * 
    * @param integer $userId 
    * @return Mybox 
    */ 
    public function setUserId($userId) 
    { 
     $this->user_id = $userId; 

     return $this; 
    } 

    /** 
    * Get user_id 
    * 
    * @return integer 
    */ 
    public function getUserId() 
    { 
     return $this->user_id; 
    } 
} 

PaypalPayment:(很多)

<?php 
namespace Pp\CreditBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Doctrine\Common\Collections\ArrayCollection; 

/** 
* @ORM\Entity(repositoryClass="Pp\CreditBundle\Repository\PaypalPaymentRepository") 
* @ORM\Table(name="paypal_payment") 
*/ 
class PaypalPayment 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 


    /** 
    * @ORM\ManyToOne(targetEntity="Pp\UserBundle\Entity\User") 
    * @ORM\JoinColumn(name="user_id", referencedColumnName="id") 
    */ 
    protected $user; 

    /** 
    * @ORM\ManyToOne(targetEntity="Pp\CoreBundle\Entity\Mybox") 
    * @ORM\JoinColumn(name="mybox_id", referencedColumnName="id") 
    */ 
    protected $mybox; 


    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 


    /** 
    * Set user 
    * 
    * @param \Pp\UserBundle\Entity\User $user 
    * @return PaypalPayment 
    */ 
    public function setUser(\Pp\UserBundle\Entity\User $user = null) 
    { 
     $this->user = $user; 

     return $this; 
    } 

    /** 
    * Get user 
    * 
    * @return \Pp\UserBundle\Entity\User 
    */ 
    public function getUser() 
    { 
     return $this->user; 
    } 

    /** 
    * Set mybox 
    * 
    * @param \Pp\CoreBundle\Entity\Mybox $mybox 
    * @return PaypalPayment 
    */ 
    public function setMybox(\Pp\CoreBundle\Entity\Mybox $mybox = null) 
    { 
     $this->mybox = $mybox; 

     return $this; 
    } 

    /** 
    * Get mybox 
    * 
    * @return \Pp\CoreBundle\Entity\Mybox 
    */ 
    public function getMybox() 
    { 
     return $this->mybox; 
    } 

} 
+0

您有'Maybox'類'mappedBy =「Mybox」',但'PaypalPayment'中的列名是'mybox'。也是'targetEntity =「Pp \ CoreBundle \ Entity \ Mybox」'而不是PaypalPayment – KhorneHoly 2014-11-04 10:20:57

回答

1

你的錯誤有以下幾條:

  1. 你在你的mappedBy有一個錯字,你寫Mybox,而不是mybox
  2. OneToMany註釋引用本身

我將inversedBy部分加入了ManyToOne,但是沒有必要!

/** 
* @ORM\ManyToOne(targetEntity="Pp\CoreBundle\Entity\Mybox", inversedBy="PaypalPayment") 
* @ORM\JoinColumn(name="mybox_id", referencedColumnName="id") 
*/ 
protected $mybox; 

/** 
* @ORM\OneToMany(targetEntity="Pp\CoreBundle\Entity\PaypalPayment", mappedBy="mybox") 
*/ 
protected $PaypalPayment;