sf-api-example/src/AppBundle/Entity/Category.php
2016-11-23 16:10:52 +01:00

118 lines
1.9 KiB
PHP

<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Category
*
* @ORM\Table(name="category")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository")
*/
class Category
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(
* targetEntity="Book",
* mappedBy="categories",
* cascade={"persist"}
* )
*/
private $books;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Category
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Constructor
*/
public function __construct()
{
$this->books = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add book
*
* @param \AppBundle\Entity\Book $book
*
* @return Category
*/
public function addBook(\AppBundle\Entity\Book $book)
{
$this->books[] = $book;
return $this;
}
/**
* Remove book
*
* @param \AppBundle\Entity\Book $book
*/
public function removeBook(\AppBundle\Entity\Book $book)
{
$this->books->removeElement($book);
}
/**
* Get books
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getBooks()
{
return $this->books;
}
}