Created
September 7, 2015 22:38
-
-
Save miguelplazasr/c183779e034ba0f22cc0 to your computer and use it in GitHub Desktop.
Entity Country 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; | |
/** | |
* AppBundle\Entity\Country | |
* | |
* @ORM\Table(name="tb_country") | |
* @ORM\Entity(repositoryClass="AppBundle\Entity\CountryRepository") | |
*/ | |
class Country { | |
/** | |
* @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\OneToMany(targetEntity="State", mappedBy="country", cascade={"persist", "remove"}) | |
*/ | |
Private $states; | |
public function __toString() { | |
return $this->name; | |
} | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
$this->states = new \Doctrine\Common\Collections\ArrayCollection(); | |
} | |
/** | |
* Set id | |
* | |
* @param string $id | |
* @return Country | |
*/ | |
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 Country | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
return $this; | |
} | |
/** | |
* Get name | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* Add states | |
* | |
* @param State $states | |
* @return Country | |
*/ | |
public function addState(State $states) | |
{ | |
$this->states[] = $states; | |
return $this; | |
} | |
/** | |
* Remove states | |
* | |
* @param State $states | |
*/ | |
public function removeState(State $states) | |
{ | |
$this->states->removeElement($states); | |
} | |
/** | |
* Get states | |
* | |
* @return \Doctrine\Common\Collections\Collection | |
*/ | |
public function getStates() | |
{ | |
return $this->states; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment