Doctrine加入表以获得相同的ID



我是symfony的初学者,我必须使用收集表格创建一个网站来预订演出门票。

界面很简单,用户可以选择他想要的彩票数量,然后显示所需的表格原型(姓名和姓氏输入)。这部分对我来说很好。

每次提交=新预订

我在mysql中有两个表"预订"one_answers"票证",我想在提交表单后得到这个渲染:

餐桌预订:

预订id="1">

预订id="2">

表坯料:

钢坯id="1"name="thomas",姓氏="good",reservation_id="1">

Billet id="2"name="laura",姓氏="高级",reservation_id="1">

钢坯id="3"name="pierre",姓氏="martin",reservation_id="2">


问题是我得到了这个结果:

钢坯id="1"name="thomas",姓氏="good",reservation_id="Null">

钢坯id="2"name="laura",姓氏="高级",reservation_id="Null">


这是我的实体:

<?php
namespace LouvrePagesBundleEntity;
use DoctrineORMMapping as ORM;
/**
* Billet
*
* @ORMTable(name="billet")
* @ORMEntity(repositoryClass="LouvrePagesBundleRepositoryBilletRepository")
*/
class Billet
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORMManyToOne(targetEntity="Reservations", inversedBy="billets")
* @ORMJoinColumn(name="reservations_id", referencedColumnName="id")
*/
protected $reservations;
/**
* @var string
*
* @ORMColumn(name="prenom", type="string", length=255)
*/
private $prenom;
/**
* @var string
*
* @ORMColumn(name="nom", type="string", length=255)
*/
private $nom;

/**
* Get id
*
* @return integer 
*/
public function getId()
{
return $this->id;
}
/**
* Set prenom
*
* @param string $prenom
* @return Billet
*/
public function setPrenom($prenom)
{
$this->prenom = $prenom;
return $this;
}
/**
* Get prenom
*
* @return string 
*/
public function getPrenom()
{
return $this->prenom;
}
/**
* Set nom
*
* @param string $nom
* @return Billet
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string 
*/
public function getNom()
{
return $this->nom;
}
}

<?php
namespace LouvrePagesBundleEntity;
use DoctrineORMMapping as ORM;
use DoctrineCommonCollectionsArrayCollection;
/**
* Reservations
*
* @ORMTable(name="reservations")
* @ORMEntity(repositoryClass="LouvrePagesBundleRepositoryReservationsRepository")
*/
class Reservations
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;

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

/**
* @ORMOneToMany(targetEntity="Billet", mappedBy="reservations", cascade={"persist","remove"})
*/
protected $billets;

public function __construct()
{
$this->billets = new ArrayCollection();
}
public function getBillets()
{
return $this->billets;
}
public function setBillets(ArrayCollection $billets)
{
$this->billets = $billets;
}
}

您的命名有点混乱。。。

我建议:

class Billet
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORMManyToOne(targetEntity="Reservation", inversedBy="billets")
* @ORMJoinColumn(name="reservation_id", referencedColumnName="id")
*/
protected $reservation;
/**
* @var string
*
* @ORMColumn(name="prenom", type="string", length=255)
*/
private $prenom;
/**
* @var string
*
* @ORMColumn(name="nom", type="string", length=255)
*/
private $nom;

/**
* Get id
*
* @return integer 
*/
public function getId()
{
return $this->id;
}
/**
* Set prenom
*
* @param string $prenom
* @return Billet
*/
public function setPrenom($prenom)
{
$this->prenom = $prenom;
return $this;
}
/**
* Get prenom
*
* @return string 
*/
public function getPrenom()
{
return $this->prenom;
}
/**
* Set nom
*
* @param string $nom
* @return Billet
*/
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
/**
* Get nom
*
* @return string 
*/
public function getNom()
{
return $this->nom;
}
public function setReservation(Reservation $reservation)
{
$this->reservation = $reservation;
return $this;
}
public function getReservation()
{
return $this->reservation;
}
}  

Reservation实体

/**
* Reservation
*
* @ORMTable(name="reservations")
* @ORMEntity(repositoryClass="LouvrePagesBundleRepositoryReservationsRepository")
*/
class Reservation
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;

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

/**
* @ORMOneToMany(targetEntity="Billet", mappedBy="reservations", cascade={"persist","remove"})
*/
protected $billets;

public function __construct()
{
$this->billets = new ArrayCollection();
}
public function getBillets()
{
return $this->billets;
}
public function addBillet(Billet $billet)
{
if (!$this->billets->contains($billet))
{
$this->billets->add($billet);
$billet->setReservation($this);
}
return $this;
}
public function removeBillet(Billet $billet)
{
// you can implement for collection
}
public function setBillets($billets)
{
$this->billets = new ArrayCollection();
foreach ($billets as $billet)
{
$this->addBillet($billet)
}
return $this;
}
}   

相关内容

  • 没有找到相关文章