Created
September 7, 2015 22:41
-
-
Save miguelplazasr/5b077c6b724653cc8559 to your computer and use it in GitHub Desktop.
Entity State for Symfony Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
/** | |
* AppBundle\Entity\State | |
* | |
* @ORM\Table(name="tb_state") | |
* @ORM\Entity(repositoryClass="AppBundle\Entity\StateRepository") | |
*/ | |
class State { | |
/** | |
* @var integer $id | |
* | |
* @ORM\Id | |
* @ORM\Column(type="string") | |
* @ORM\GeneratedValue(strategy="NONE") | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(type="string") | |
* @Assert\NotBlank() | |
* @Assert\Length( max = "100" ) | |
*/ | |
protected $name; | |
/** | |
* @ORM\ManyToOne(targetEntity="Country", inversedBy="states") | |
* @ORM\JoinColumn(name="country_id", referencedColumnName="id") | |
*/ | |
protected $country; | |
/** | |
* @ORM\OneToMany(targetEntity="City", mappedBy="state", cascade={"persist", "remove"}) | |
*/ | |
Private $cities; | |
public function __toString() { | |
return $this->name; | |
} | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
$this->cities = new \Doctrine\Common\Collections\ArrayCollection(); | |
} | |
/** | |
* Set id | |
* | |
* @param string $id | |
* @return State | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
return $this; | |
} | |
/** | |
* Get id | |
* | |
* @return string | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set name | |
* | |
* @param string $name | |
* @return State | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
return $this; | |
} | |
/** | |
* Get name | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* Set country | |
* | |
* @param Country $country | |
* @return State | |
*/ | |
public function setCountry(Country $country = null) | |
{ | |
$this->country = $country; | |
return $this; | |
} | |
/** | |
* Get country | |
* | |
* @return Country | |
*/ | |
public function getCountry() | |
{ | |
return $this->country; | |
} | |
/** | |
* Add cities | |
* | |
* @param City $cities | |
* @return State | |
*/ | |
public function addCity(City $cities) | |
{ | |
$this->cities[] = $cities; | |
return $this; | |
} | |
/** | |
* Remove cities | |
* | |
* @param City $cities | |
*/ | |
public function removeCity(City $cities) | |
{ | |
$this->cities->removeElement($cities); | |
} | |
/** | |
* Get cities | |
* | |
* @return \Doctrine\Common\Collections\Collection | |
*/ | |
public function getCities() | |
{ | |
return $this->cities; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment