I am working on my first project using Doctrine and I am stumbled on this.
I have an entity User which is a mapped super class.
/** * @ORM\MappedSuperclass */ abstract class User { /** * @var int */ protected $id; /** * @var string */ protected $name; /** * @ORM\Embedded(class="AppBundle\Entity\Person") * @var Person */ protected $person; /** * @var Authors[]|Collection|Selectable */ protected $authors; }
I create an author entity from the User entity above
class Author extends User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @var int
*/
protected $id;
/**
* @ORM\JoinColumn(name="publisher_id", referencedColumnName="id", nullable=false, unique=true)
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Publisher", inversedBy="book")
* @var Publisher
*/
protected $publisher;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Publisher", mappedBy="author")
* @var Approval[]|Collection|Selectable
*/
protected $approvals;
}
I create an object entity Book using the Author entity
/** * @ORM\Entity * @ORM\Table(name="magazine", options={"collate":"utf8_general_ci"}) */ class Book { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") * @var int */ protected $id; /** * @ORM\JoinColumn(name="publisher_id", referencedColumnName="id", nullable=false, unique=true) * @ORM\OneToOne(targetEntity="AppBundle\Entity\Publisher", inversedBy="book") * @var Publisher */ protected $publisher; }
And my Publisher entity is as below:
/**
* @ORM\Entity
* @ORM\Table(name="ops_approval", options={"collate":"utf8_general_ci"})
*/
class Publisher
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @var int
*/
protected $id;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
protected $createdAt;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Author", inversedBy="authors")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id")
*/
protected $author;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Book", mappedBy="book"
*/
protected $book;
}
Now, can I extend published entity to create a Book entity
/** * @ORM\Entity * @ORM\Table(name="book", options={"collate":"utf8_general_ci"}) */ class Book extends Magazine { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") * @var int */ protected $id; /** * @ORM\JoinColumn(name="published_id", referencedColumnName="id", nullable=false, unique=true) * @ORM\OneToOne(targetEntity="AppBundle\Entity\Publisher", inversedBy="book") * @var Publisher */ protected $publisher; }