Skip to content

Commit 2a2a594

Browse files
committed
Add Pictures to Restaurant
1 parent e7d73e0 commit 2a2a594

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Entity/Restaurant.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Entity;
44

5+
use Doctrine\Common\Collections\ArrayCollection;
6+
use Doctrine\Common\Collections\Collection;
57
use Doctrine\ORM\Mapping as ORM;
68

79
/**
@@ -32,6 +34,16 @@ class Restaurant
3234
*/
3335
private $city;
3436

37+
/**
38+
* @ORM\OneToMany(targetEntity="App\Entity\RestaurantPicture", mappedBy="restaurant", orphanRemoval=true)
39+
*/
40+
private $restaurantPictures;
41+
42+
public function __construct()
43+
{
44+
$this->restaurantPictures = new ArrayCollection();
45+
}
46+
3547
public function getId(): ?int
3648
{
3749
return $this->id;
@@ -72,4 +84,35 @@ public function setCity(?City $city): self
7284

7385
return $this;
7486
}
87+
88+
/**
89+
* @return Collection|RestaurantPicture[]
90+
*/
91+
public function getRestaurantPictures(): Collection
92+
{
93+
return $this->restaurantPictures;
94+
}
95+
96+
public function addRestaurantPicture(RestaurantPicture $restaurantPicture): self
97+
{
98+
if (!$this->restaurantPictures->contains($restaurantPicture)) {
99+
$this->restaurantPictures[] = $restaurantPicture;
100+
$restaurantPicture->setRestaurant($this);
101+
}
102+
103+
return $this;
104+
}
105+
106+
public function removeRestaurantPicture(RestaurantPicture $restaurantPicture): self
107+
{
108+
if ($this->restaurantPictures->contains($restaurantPicture)) {
109+
$this->restaurantPictures->removeElement($restaurantPicture);
110+
// set the owning side to null (unless already changed)
111+
if ($restaurantPicture->getRestaurant() === $this) {
112+
$restaurantPicture->setRestaurant(null);
113+
}
114+
}
115+
116+
return $this;
117+
}
75118
}

src/Entity/RestaurantPicture.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,26 @@ class RestaurantPicture
1616
*/
1717
private $id;
1818

19+
/**
20+
* @ORM\ManyToOne(targetEntity="App\Entity\Restaurant", inversedBy="restaurantPictures")
21+
* @ORM\JoinColumn(nullable=false)
22+
*/
23+
private $restaurant;
24+
1925
public function getId(): ?int
2026
{
2127
return $this->id;
2228
}
29+
30+
public function getRestaurant(): ?Restaurant
31+
{
32+
return $this->restaurant;
33+
}
34+
35+
public function setRestaurant(?Restaurant $restaurant): self
36+
{
37+
$this->restaurant = $restaurant;
38+
39+
return $this;
40+
}
2341
}

0 commit comments

Comments
 (0)