I'm beginner on symfony and I have to use the collection form to make a site to reserve tickets for a show.
The interface is simple, The user select the number of tickets he wants, then it display as much form prototype (name and surname input) as tickets required. This part works well for me.
Every submit = new reservation
I have 2 table "reservations" and "ticket" in mysql and I would like to get this render after submiting the form:
Table reservation:
Reservation id = "1"
Reservation id = "2"
Table Billet:
Billet id="1" name="thomas", surname="good", reservation_id="1"
Billet id="2" name="laura", surname="senior", reservation_id="1"
Billet id="3" name="pierre", surname="martin", reservation_id="2"
Problem is that i get this result :
Billet id="1" name="thomas", surname="good", reservation_id="Null"
Billet id="2" name="laura", surname="senior", reservation_id="Null"
Here is my entitys:
<?php
namespace Louvre\PagesBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Billet
*
* @ORM\Table(name="billet")
* @ORM\Entity(repositoryClass="Louvre\PagesBundle\Repository\BilletRepository")
*/
class Billet
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Reservations", inversedBy="billets")
* @ORM\JoinColumn(name="reservations_id", referencedColumnName="id")
*/
protected $reservations;
/**
* @var string
*
* @ORM\Column(name="prenom", type="string", length=255)
*/
private $prenom;
/**
* @var string
*
* @ORM\Column(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 Louvre\PagesBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Reservations
*
* @ORM\Table(name="reservations")
* @ORM\Entity(repositoryClass="Louvre\PagesBundle\Repository\ReservationsRepository")
*/
class Reservations
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* @ORM\OneToMany(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;
}
}