php - Symfony2 doctrine join OneToMany don't work -



php - Symfony2 doctrine join OneToMany don't work -

i have 2 connected entities in onetomany connection, when seek query them out next error

notice: undefined index: mybox in /var/www/pp/vendor/doctrine/orm/lib/doctrine/orm/query/sqlwalker.php line 887

my entities next : mybox (one)

<?php namespace pp\corebundle\entity; utilize doctrine\orm\mapping orm; utilize doctrine\common\collections\arraycollection; utilize gedmo\mapping\annotation 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 paypal array. $this->paypalpayment = new \doctrine\common\collections\arraycollection(); } /** * id * * @return integer */ public function getid() { homecoming $this->id; } /** * set user * * @param \pp\userbundle\entity\user $user * @return mybox */ public function setuser(\pp\userbundle\entity\user $user = null) { $this->user = $user; homecoming $this; } /** * user * * @return \pp\userbundle\entity\user */ public function getuser() { homecoming $this->user; } /** * add together paypalpayment * * @param \pp\creditbundle\entity\mybox $paypalpayment * @return mybox */ public function addpaypalpayment(\pp\creditbundle\entity\paypalpayment $paypalpayment) { $this->paypalpayment[] = $paypalpayment; homecoming $this; } /** * remove paypalpayment * * @param \pp\creditbundle\entity\mybox $paypalpayment */ public function removepaypalpayment(\pp\creditbundle\entity\paypalpayment $paypalpayment) { $this->paypalpayment->removeelement($paypalpayment); } /** * paypalpayment * * @return \doctrine\common\collections\collection */ public function getpaypalpayment() { homecoming $this->paypalpayment; } /** * payments type in array * * @return array */ public function getpayments() { $allpayments = array(); foreach ( $this->getpaypalpayment() $paypalpayment ) { $allpayments[] = $paypalpayment; } homecoming $allpayments; } /** * set user_id * * @param integer $userid * @return mybox */ public function setuserid($userid) { $this->user_id = $userid; homecoming $this; } /** * user_id * * @return integer */ public function getuserid() { homecoming $this->user_id; } }

paypalpayment: (many)

<?php namespace pp\creditbundle\entity; utilize doctrine\orm\mapping orm; utilize 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; /** * id * * @return integer */ public function getid() { homecoming $this->id; } /** * set user * * @param \pp\userbundle\entity\user $user * @return paypalpayment */ public function setuser(\pp\userbundle\entity\user $user = null) { $this->user = $user; homecoming $this; } /** * user * * @return \pp\userbundle\entity\user */ public function getuser() { homecoming $this->user; } /** * set mybox * * @param \pp\corebundle\entity\mybox $mybox * @return paypalpayment */ public function setmybox(\pp\corebundle\entity\mybox $mybox = null) { $this->mybox = $mybox; homecoming $this; } /** * mybox * * @return \pp\corebundle\entity\mybox */ public function getmybox() { homecoming $this->mybox; } }

your mistakes following:

you had typo in mappedby, wrote mybox instead of mybox your onetomany annotation referenced itself

i added inversedby part manytoone, though ain't necessary!

/** * @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;

php symfony2 doctrine2 doctrine

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -