Hi,
I need some help, I work on ZF2 with doctrine 2. I have one entity: TaFoo
with children : TaBar (ArrayCollection) . TaBar has also children: ATypeBar
(ArrayCollection) associate to TypeBar. I use FieldSets to add multiple
TaBars and on each TaBar I want add multiple ATypeBars.
But when I save:
- TaFoo is create and save
- TaBar are also create and save
- TaTypeBar save only the last collection
*I don't have any error but the firsts under collections are never save.*
I don't know if it's a Entities problem or Controller problem.
*Entity:*
*TaFoo*
class TaFoo{
/**
* @var integer
* @ORM\Column(name="ID_FOO", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="TA_FOO_ID_FOO_seq",
allocationSize=1, initialValue=1)
*/
private $idFoo;
/**
* Get idFoo
*
* @return integer
*/
public function getIdFoo()
{
return $this->idFoo;
}
/**
* @ORM\OneToMany(targetEntity="TaBar", mappedBy="idFoo",
cascade={"persist", "remove"}, orphanRemoval=true)
**/
private $idBar;
/**
* Get idBar
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getIdBar()
{
return $this->idBar;
}
/**
* Remove idBar
*
* @param \Doctrine\Common\Collections\Collection $idBar
*/
public function removeIdBar(\Doctrine\Common\Collections\Collection
$idBars)
{
foreach ($idBars as $idBar) {
$idBar->setIdFoo(null);
$this->idBar->removeElement($idBar);
}
}
/**
* Add idBar
*
* @param \Doctrine\Common\Collections\Collection $idBar
* @return TaFoo
*/
public function addIdBar(\Doctrine\Common\Collections\Collection
$idBars)
{
foreach ($idBars as $idBar) {
$idBar->setIdFoo($this);
$this->idBar->add($idBar);
}
return $this;
}}
*TaBar*
class TaBar {
// **************************************************TYPE
BAR***************************************************/**
* @ORM\OneToMany(targetEntity="Application\Entity\ATypeBar", mappedBy="idBar",
cascade={"persist", "remove"}, orphanRemoval=true)
* */private $idATypeBars;
/**
* Get typeBar
* @return \Doctrine\Common\Collections\Collection
*/public function getIdATypeBars() {
return $this->idATypeBars;}
/**
* Remove typeBar
* @param \Doctrine\Common\Collections\Collection $typeBars
*/public function removeIdATypeBars(\Doctrine\Common\Collections\Collection
$idATypeBars) {
foreach ($idATypeBars as $idATypeBar) {
$idATypeBar->setIdBar(null);
$this->idATypeBars->removeElement($idATypeBar);
}}
/**
* Add typeBar
* @param \Doctrine\Common\Collections\Collection $typeBars
* @return TaBar
*/public function addIdATypeBars(\Doctrine\Common\Collections\Collection
$idATypeBars) {
foreach ($idATypeBars as $idATypeBar) {
$idATypeBar->setIdBar($this);
$this->idATypeBars->add($idATypeBar);
}
return $this;}
*ATypeBar*
class ATypeBar{
/**
* @var integer
*
* @ORM\Column(name="ID_A_TYPE_Bar", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="A_TYPE_Bar_ID_A_TYPE_Bar_seq",
allocationSize=1, initialValue=1)
*/
private $idATypeBar;
/**
* @var \Application\Entity\TaBar
*
*
@ORM\ManyToOne(targetEntity="Application\Entity\TaBar",cascade={"persist"},inversedBy="idATypeBar")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="ID_Bar", referencedColumnName="ID_Bar")
* })
*/
private $idBar;
/**
* @var \Application\Entity\TaTypeBar
*
* @ORM\ManyToOne(targetEntity="Application\Entity\TaTypeBar")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="ID_TYPE_Bar", referencedColumnName="ID_TYPE_Bar")
* })
*/
private $idTypeBar;
/**
* Get idATypeBar
*
* @return integer
*/
public function getIdATypeBar()
{
return $this->idATypeBar;
}
/**
* Set idBar
*
* @param \Application\Entity\TaBar $idBar
* @return ATypeBar
*/
public function setIdBar(\Application\Entity\TaBar $idBar = null)
{
$this->idBar = $idBar;
return $this;
}
/**
* Get idBar
*
* @return \Application\Entity\TaBar
*/
public function getIdBar()
{
return $this->idBar;
}
/**
* Set idTypeBar
*
* @param \Application\Entity\TaTypeBar $idTypeBar
* @return ATypeBar
*/
public function setIdTypeBar(\Application\Entity\TaTypeBar $idTypeBar =
null)
{
$this->idTypeBar = $idTypeBar;
return $this;
}
/**
* Get idTypeBar
*
* @return \Application\Entity\TaTypeBar
*/
public function getIdTypeBaru()
{
return $this->idTypeBar;
}}
*TaTypeBar*
*class TaTypeBar { /** * @ORM\OneToMany(targetEntity="ATypeBar",
mappedBy="idTypeBar", cascade={"persist", "remove"}, orphanRemoval=true)
* */ private $typeBar; /** * @var integer * *
@ORM\Column(name="ID_TYPE_Bar", type="integer", nullable=false) *
@ORM\Id * @ORM\GeneratedValue(strategy="SEQUENCE") *
@ORM\SequenceGenerator(sequenceName="TA_TYPE_BarDE_ID_TYPE_Bar_seq",
allocationSize=1, initialValue=1) */ private $idTypeBar; /**
* Constructor */ public function __construct() {
$this->idBar = new \Doctrine\Common\Collections\ArrayCollection(); }
/** * Get idTypeBar * * @return integer */ public
function getIdTypeBar() { return $this->idTypeBar; } /** *
Add idBar * * @param \Application\Entity\TaBar $idBar * @return
TaTypeBar */ public function addIdBar(\Application\Entity\TaBar
$idBar) { $this->idBar[] = $idBar; return $this;
}}Controller FooController*
* $request = $this->getRequest(); $idFoo = (int)
$this->params()->fromRoute('id', 0); if ($request->isPost()) {
$idFoo = $this->params()->fromPost('idFoo'); } $taFoo =
$this->getEntityManager()->find('\Application\Entity\TaFoo', $idFoo);
$form = new FooForm($this->getEntityManager(), $this->getUserNum());
$form->bind($taFoo); if ($request->isPost()) { $post =
$request->getPost(); $config =
$this->getServiceLocator()->get('config'); $fieldset =
$config['fieldset']; $form->setData($post); if
($form->isValid()) {
$this->getEntityManager()->persist($taFoo);
$this->getEntityManager()->flush(); echo ('ok');
exit(); } echo '-1: '; print_r($form->getMessages());
exit();I have already check if datas are correct in $request->getPost
and it's ok. All datas to save TaFoo/TaBar/AtypeBar/TaTypeBar are in. But
the persist don't work with TaTypeBar.*
Any ideas? Or someone saw this problem?
Thank you in advance for your answers :)
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.