src/Core/Entity/City.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Core\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. /**
  8. * @ORM\Entity(repositoryClass="App\Core\Repository\CityRepository")
  9. */
  10. class City
  11. {
  12. /**
  13. * @ORM\Id()
  14. * @ORM\GeneratedValue()
  15. * @ORM\Column(type="integer")
  16. * @Groups("city")
  17. */
  18. private $id;
  19. /**
  20. * @ORM\Column(type="string", length=50)
  21. * @Groups("city")
  22. */
  23. private $nombre;
  24. /**
  25. * @ORM\OneToMany(targetEntity="App\Core\Entity\Direccion", mappedBy="city")
  26. */
  27. private $direcciones;
  28. /**
  29. * @ORM\ManyToOne(targetEntity="App\Core\Entity\State", inversedBy="cities")
  30. */
  31. private $state;
  32. public function __construct()
  33. {
  34. $this->direcciones = new ArrayCollection();
  35. }
  36. public function getId(): ?int
  37. {
  38. return $this->id;
  39. }
  40. public function getNombre(): ?string
  41. {
  42. return $this->nombre;
  43. }
  44. public function setNombre(string $nombre): self
  45. {
  46. $this->nombre = $nombre;
  47. return $this;
  48. }
  49. /**
  50. * @return Collection|Direccion[]
  51. */
  52. public function getDirecciones(): Collection
  53. {
  54. return $this->direcciones;
  55. }
  56. public function addDireccion(Direccion $direccion): self
  57. {
  58. if (!$this->direcciones->contains($direccion)) {
  59. $this->direcciones[] = $direccion;
  60. $direccion->setCity($this);
  61. }
  62. return $this;
  63. }
  64. public function removeDireccion(Direccion $direccion): self
  65. {
  66. if ($this->direcciones->contains($direccion)) {
  67. $this->direcciones->removeElement($direccion);
  68. // set the owning side to null (unless already changed)
  69. if ($direccion->getCity() === $this) {
  70. $direccion->setCity(null);
  71. }
  72. }
  73. return $this;
  74. }
  75. public function getState(): ?State
  76. {
  77. return $this->state;
  78. }
  79. public function setState(?State $state): self
  80. {
  81. $this->state = $state;
  82. return $this;
  83. }
  84. }