Doctrine: entities
This commit is contained in:
parent
2cc9bc4b65
commit
a34aa1b91f
144
src/AppBundle/Entity/Author.php
Normal file
144
src/AppBundle/Entity/Author.php
Normal file
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* Author
|
||||
*
|
||||
* @ORM\Table(name="author")
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\AuthorRepository")
|
||||
*/
|
||||
class Author
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="firstname", type="string", length=255)
|
||||
*/
|
||||
private $firstname;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="lastname", type="string", length=255)
|
||||
*/
|
||||
private $lastname;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Common\Collections\Collection
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity="Book", mappedBy="author", cascade={"persist"})
|
||||
*/
|
||||
private $books;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set firstname
|
||||
*
|
||||
* @param string $firstname
|
||||
*
|
||||
* @return Author
|
||||
*/
|
||||
public function setFirstname($firstname)
|
||||
{
|
||||
$this->firstname = $firstname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get firstname
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstname()
|
||||
{
|
||||
return $this->firstname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lastname
|
||||
*
|
||||
* @param string $lastname
|
||||
*
|
||||
* @return Author
|
||||
*/
|
||||
public function setLastname($lastname)
|
||||
{
|
||||
$this->lastname = $lastname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lastname
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastname()
|
||||
{
|
||||
return $this->lastname;
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->books = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add book
|
||||
*
|
||||
* @param \AppBundle\Entity\Book $book
|
||||
*
|
||||
* @return Author
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
234
src/AppBundle/Entity/Book.php
Normal file
234
src/AppBundle/Entity/Book.php
Normal file
|
@ -0,0 +1,234 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* Book.
|
||||
*
|
||||
* @ORM\Table(name="book")
|
||||
* @ORM\Entity(repositoryClass="AppBundle\Repository\BookRepository")
|
||||
*/
|
||||
class Book
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="title", type="string", length=255)
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(name="pages", type="integer")
|
||||
*/
|
||||
private $pages;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="publishedAt", type="date")
|
||||
*/
|
||||
private $publishedAt;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Common\Collections\Collection
|
||||
*
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Category",
|
||||
* cascade={"persist"}
|
||||
* )
|
||||
* @ORM\JoinTable(
|
||||
* name="book_has_category",
|
||||
* joinColumns={
|
||||
* @ORM\JoinColumn(
|
||||
* name="book_id",
|
||||
* referencedColumnName="id"
|
||||
* )
|
||||
* },
|
||||
* inverseJoinColumns={
|
||||
* @ORM\JoinColumn(
|
||||
* name="category_id",
|
||||
* referencedColumnName="id",
|
||||
* unique=true
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
private $categories;
|
||||
|
||||
/**
|
||||
* @var Author
|
||||
*
|
||||
* @ORM\ManyToOne(
|
||||
* targetEntity="Author",
|
||||
* inversedBy="books",
|
||||
* cascade={"persist", "remove", "merge"}
|
||||
* )
|
||||
* @ORM\JoinColumn(
|
||||
* name="author_id",
|
||||
* referencedColumnName="id"
|
||||
* )
|
||||
*/
|
||||
private $author;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title.
|
||||
*
|
||||
* @param string $title
|
||||
*
|
||||
* @return Book
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set pages.
|
||||
*
|
||||
* @param int $pages
|
||||
*
|
||||
* @return Book
|
||||
*/
|
||||
public function setPages($pages)
|
||||
{
|
||||
$this->pages = $pages;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pages.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPages()
|
||||
{
|
||||
return $this->pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set publishedAt.
|
||||
*
|
||||
* @param \DateTime $publishedAt
|
||||
*
|
||||
* @return Book
|
||||
*/
|
||||
public function setPublishedAt($publishedAt)
|
||||
{
|
||||
$this->publishedAt = $publishedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get publishedAt.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getPublishedAt()
|
||||
{
|
||||
return $this->publishedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add category
|
||||
*
|
||||
* @param \AppBundle\Entity\Category $category
|
||||
*
|
||||
* @return Book
|
||||
*/
|
||||
public function addCategory(\AppBundle\Entity\Category $category)
|
||||
{
|
||||
$this->categories[] = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove category
|
||||
*
|
||||
* @param \AppBundle\Entity\Category $category
|
||||
*/
|
||||
public function removeCategory(\AppBundle\Entity\Category $category)
|
||||
{
|
||||
$this->categories->removeElement($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get categories
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getCategories()
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set author
|
||||
*
|
||||
* @param \AppBundle\Entity\Author $author
|
||||
*
|
||||
* @return Book
|
||||
*/
|
||||
public function setAuthor(\AppBundle\Entity\Author $author = null)
|
||||
{
|
||||
$this->author = $author;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get author
|
||||
*
|
||||
* @return \AppBundle\Entity\Author
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->author;
|
||||
}
|
||||
}
|
117
src/AppBundle/Entity/Category.php
Normal file
117
src/AppBundle/Entity/Category.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
13
src/AppBundle/Repository/AuthorRepository.php
Normal file
13
src/AppBundle/Repository/AuthorRepository.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Repository;
|
||||
|
||||
/**
|
||||
* AuthorRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class AuthorRepository extends \Doctrine\ORM\EntityRepository
|
||||
{
|
||||
}
|
13
src/AppBundle/Repository/BookRepository.php
Normal file
13
src/AppBundle/Repository/BookRepository.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Repository;
|
||||
|
||||
/**
|
||||
* BookRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class BookRepository extends \Doctrine\ORM\EntityRepository
|
||||
{
|
||||
}
|
13
src/AppBundle/Repository/CategoryRepository.php
Normal file
13
src/AppBundle/Repository/CategoryRepository.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Repository;
|
||||
|
||||
/**
|
||||
* CategoryRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class CategoryRepository extends \Doctrine\ORM\EntityRepository
|
||||
{
|
||||
}
|
Loading…
Reference in a new issue