I have two Entities, one for reservations and one for tables where the reservations can be placed on. This entities have a ManyToMany relation. When I try to validate this schema I get the following errors:
Can I get some help with this? I can't figure out what I'm doing wrong.
Table Entity:
/**
*
* @ORM\Entity
* @ORM\Table(name="tables")
* @ORM\Entity(repositoryClass="Test\TestBundle\Repository\TableRepository")
*/
class Table {
/**
* @var integer $id
* @ORM\ID
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="integer", length=3)
*/
protected $nmbr;
/**
* @ORM\ManyToMany(targetEntity="Reservation", mappedBy="tables", cascade={"persist"})
*/
private $reservations;
public function addReservation($reservation) {
$reservation->addTable($this);
$this->reservations[] = $reservation;
}
public function getId() {
return $this->id;
}
public function getNmbr() {
return $this->nmbr;
}
public function getReservations() {
return $this->reservations;
}
public function setId($id) {
$this->id = $id;
}
public function setNmbr($nmbr) {
$this->nmbr = $nmbr;
}
/**
* overrides the array of reservations belonging to this tabke in $reservations
* with the given array of reservations.
* Also adds this table to every reservations in the array.
*
*/
public function setReservations($reservations) {
foreach ($reservations as $reservation) {
$reservation->addTable($this);
}
$this->reservations = $reservation;
}
public function __toString() {
return (string)$this->getNmbr();
}
public function __construct() {
parent::__construct();
$this->reservations = new ArrayCollection();
}
Reservation Entity:
/**
* @ORM\Entity(repositoryClass="Test\TestBundle\Repository\ReservationRepository")
* @ORM\Table(name="reservations")
* @ORM\HasLifecycleCallbacks()
*/
class Reservation {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="Table", inversedBy="tables")
* @ORM\JoinTable(name="reservation_table")
**/
protected $tables;
/**
* @ORM\Column(type="string", length=32)
*/
protected $firstname;
/**
* @ORM\Column(type="string", length=32)
*/
protected $lastname;
/**
* @ORM\Column(type="string", length=32)
*/
protected $phone;
/**
* @ORM\Column(type="string", length=32)
*/
protected $email;
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $message;
/**
* @ORM\Column(type="date")
*/
protected $date;
/**
* @ORM\Column(type="string", length=32)
*/
protected $timeFrom;
/**
* @ORM\Column(type="string", length=32)
*/
protected $timeTo;
public function addTable($table) {
$this->tables[] = $table;
}
public function getTables() {
return $this->tables;
}
public function getId() {
return $this->id;
}
public function getFirstname() {
return $this->firstname;
}
public function getLastname() {
return $this->lastname;
}
public function getPhone() {
return $this->phone;
}
public function getEmail() {
return $this->email;
}
public function getMessage() {
return $this->message;
}
public function getDate() {
return $this->date;
}
public function getTimeFrom() {
return $this->timeFrom;
}
public function getTimeTo() {
return $this->timeTo;
}
public function setId($id) {
$this->id = $id;
}
public function setTables($tables) {
$this->tables = $tables;
}
public function setFirstname($firstname) {
$this->firstname = $firstname;
}
public function setLastname($lastname) {
$this->lastname = $lastname;
}
public function setPhone($phone) {
$this->phone = $phone;
}
public function setEmail($email) {
$this->email = $email;
}
public function setMessage($message) {
$this->message = $message;
}
public function setDate($date) {
$this->date = $date;
}
public function setTimeFrom($timeFrom) {
$this->timeFrom = $timeFrom;
}
public function setTimeTo($timeTo) {
$this->timeTo = $timeTo;
}
public function __construct() {
$this->tables = new \Doctrine\Common\Collections\ArrayCollection();
}
In Reservation
entity inversedBy
property, you should point the appropriate field, so resevations
, not tables
:
/**
* @ORM\ManyToMany(targetEntity="Table", inversedBy="reservations")
* @ORM\JoinTable(name="reservation_table")
**/
protected $tables;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With