Commit 657042b6 by Lech Sawon

migration and changes

parent d68905ba
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20211025132503 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reservation ADD CONSTRAINT FK_42C8495554177093 FOREIGN KEY (room_id) REFERENCES room (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_42C8495554177093 ON reservation (room_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE reservation DROP CONSTRAINT FK_42C8495554177093');
$this->addSql('DROP INDEX IDX_42C8495554177093');
}
}
...@@ -18,9 +18,10 @@ class Reservation ...@@ -18,9 +18,10 @@ class Reservation
private $id; private $id;
/** /**
* @ORM\Column(type="integer") * @ORM\ManyToOne(targetEntity="Room")
* @ORM\JoinColumn(name="room_id", referencedColumnName="id", nullable=false)
*/ */
private $roomId; private Room $room;
/** /**
* @ORM\Column(type="datetime") * @ORM\Column(type="datetime")
...@@ -37,18 +38,21 @@ class Reservation ...@@ -37,18 +38,21 @@ class Reservation
return $this->id; return $this->id;
} }
public function getRoomId(): ?int public function getRoom(): Room
{ {
return $this->roomId; return $this->room;
} }
public function setRoomId(int $roomId): self /**
* @param Room $room
*/
public function setRoom(Room $room): void
{ {
$this->roomId = $roomId; $this->room = $room;
return $this;
} }
public function getDateFrom(): ?\DateTimeInterface public function getDateFrom(): ?\DateTimeInterface
{ {
return $this->dateFrom; return $this->dateFrom;
......
...@@ -38,4 +38,9 @@ class Room ...@@ -38,4 +38,9 @@ class Room
return $this; return $this;
} }
public function __toString(): string
{
return $this->getName();
}
} }
...@@ -12,7 +12,7 @@ class ReservationType extends AbstractType ...@@ -12,7 +12,7 @@ class ReservationType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder $builder
->add('roomId') ->add('room')
->add('dateFrom') ->add('dateFrom')
->add('dateEnd') ->add('dateEnd')
; ;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
{% for reservation in reservations %} {% for reservation in reservations %}
<tr> <tr>
<td>{{ reservation.id }}</td> <td>{{ reservation.id }}</td>
<td>{{ reservation.roomId }}</td> <td>{{ reservation.room }}</td>
<td>{{ reservation.dateFrom ? reservation.dateFrom|date('Y-m-d H:i:s') : '' }}</td> <td>{{ reservation.dateFrom ? reservation.dateFrom|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ reservation.dateEnd ? reservation.dateEnd|date('Y-m-d H:i:s') : '' }}</td> <td>{{ reservation.dateEnd ? reservation.dateEnd|date('Y-m-d H:i:s') : '' }}</td>
<td> <td>
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</tr> </tr>
<tr> <tr>
<th>RoomId</th> <th>RoomId</th>
<td>{{ reservation.roomId }}</td> <td>{{ reservation.room }}</td>
</tr> </tr>
<tr> <tr>
<th>DateFrom</th> <th>DateFrom</th>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment