I am new to Symfony. I'm working on an application where I need a cascading heritage in Doctrine, but heritage doen't appear to work :
I have a mother class, "Content" :
/**
* Content
*
* @ORM\MappedSuperclass
*/
class Content
{
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="ApiBundle\Entity\User", cascade={"persist"})
*/
private $publisher;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var text
*
* @ORM\Column(name="description", type="text", length=10000)
*/
private $description;
/**
* @var Image
*
* @ORM\ManyToOne(targetEntity="ApiBundle\Entity\Image", cascade={"persist"})
*/
private $img;
// Getters and setters
A child class extending Content
:
/**
* News
*
* @ORM\MappedSuperclass
* @ORM\Table(name="news")
* @ORM\Entity(repositoryClass="ApiBundle\Repository\NewsRepository")
*/
class News extends Content
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="publicationDate", type="datetime")
*/
private $publicationDate;
/**
* @var Association
*
* @ORM\ManyToOne(targetEntity="ApiBundle\Entity\Association", cascade={"persist"})
* @ORM\Column(name="association_id", type="integer")
*/
private $association;
// Getters and setters
And another child class that extends News
:
/**
* Events
* @ORM\MappedSuperclass
* @ORM\Table(name="event")
* @ORM\Entity(repositoryClass="ApiBundle\Repository\EventRepository")
*/
class Event extends News
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var DateTime
*
* @ORM\Column(name="eventStart", type="datetime")
*/
private $eventStart;
// Getters and setters
The problem is that in the generated SQL, News
table has a "publisher_id" and "img" column, but Event
doesn't. I can inherit regular Column
s, but I can't inherit ManyToOne ones from Content
.
Here is the generated SQL :
mysql> desc news;
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| publisher_id | int(11) | YES | MUL | NULL | |
| img_id | varchar(64) | YES | MUL | NULL | |
| title | varchar(255) | NO | | NULL | |
| description | text | NO | | NULL | |
| publicationDate | datetime | NO | | NULL | |
| association_id | int(11) | NO | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
mysql> desc event;
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(255) | NO | | NULL | |
| description | text | NO | | NULL | |
| publicationDate | datetime | NO | | NULL | |
| association_id | int(11) | NO | | NULL | |
| eventStart | datetime | NO | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
I'm using Symfony 3.2 and Doctrine 2.5.
What am I missing ? Thank you very much for your help and your time !