Multiple discrimination levels while using Doctrine2

BrandonJ

New Member
I'm using Doctrine2 to manage my model below: There's an abstract concept \[code\]Content\[/code\] with a Composite pattern in \[code\]Gallery\[/code\], also an abstract concept \[code\]Media\[/code\] from which \[code\]Video\[/code\] and \[code\]Image\[/code\] inherits.
%5BContent%5D%5E-%5BGallery%5D%2C%5BGallery%5D%3C%3E-%5BContent%5D%2C%5BContent%5D%5E-%5BMedia%5D%2C%5BMedia%5D%5E-%5BImage%5D%2C%5BMedia%5D%5E-%5BVideo%5D
My choice was to add discriminators to \[code\]Content\[/code\] and \[code\]Media\[/code\] tables in order to differentiate between \[code\]Gallery\[/code\], \[code\]Video\[/code\] and \[code\]Image\[/code\]. \[code\]Content\[/code\] uses \[code\]JOIN inheritance\[/code\] and \[code\]Media\[/code\] uses \[code\]SINGLE_TABLE inheritance\[/code\].As I run \[code\]doctrine orm:schema-tool:create --dump-sql\[/code\], \[code\]Media\[/code\] table is duplicating columns from the \[code\]Content\[/code\] one. That's the output of the command:\[code\]CREATE TABLE Content (id INT AUTO_INCREMENT NOT NULL, container_id INT DEFAULT NULL, creationDate DATETIME NOT NULL, publicationDate DATETIME DEFAULT NULL, isGallery TINYINT(1) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;CREATE TABLE Media (id INT AUTO_INCREMENT NOT NULL, creationDate DATETIME NOT NULL, publicationDate DATETIME DEFAULT NULL, width INT NOT NULL, height INT NOT NULL, isImage TINYINT(1) NOT NULL, bitrate INT NOT NULL, duration INT NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;CREATE TABLE Gallery (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;ALTER TABLE Content ADD FOREIGN KEY (container_id) REFERENCES Gallery(id);ALTER TABLE Gallery ADD FOREIGN KEY (id) REFERENCES Content(id) ON DELETE CASCADE\[/code\]Here are my classes and annotations:Content.php\[code\]/** @Entity * @InheritanceType("JOINED") * @DiscriminatorColumn(name="isGallery", type="boolean") * @DiscriminatorMap({ * 0 = "Media", * 1 = "Gallery" * }) */abstract class Content{ /** @Id @GeneratedValue @Column(type="integer") */ private $id; /** @Column(type="datetime") */ private $creationDate; /** @Column(type="datetime", nullable="true") */ private $publicationDate; /** @ManyToOne(targetEntity="Gallery", inversedBy="contents") */ private $container;}\[/code\]Media.php\[code\]/** @Entity * @InheritanceType("SINGLE_TABLE") * @DiscriminatorColumn(name="isImage", type="boolean") * @DiscriminatorMap({ * 0 = "Video", * 1 = "Image" * }) */abstract class Media extends Content{ /** @Column(type="integer") */ private $width; /** @Column(type="integer") */ private $height;}\[/code\]Gallery.php\[code\]/** @Entity */class Gallery extends Content{ /** @OneToMany(targetEntity="Content", mappedBy="container") */ private $contents;}\[/code\]Video.php\[code\]/** @Entity */class Video extends Media{ /** @Column(type="integer") */ private $bitrate; /** @Column(type="integer") */ private $duration;}\[/code\]Image.php\[code\]/** @Entity */class Image extends Media{}\[/code\]I ask: That's the correct behaviour? Should not \[code\]Media\[/code\] have only the fields \[code\]id\[/code\], \[code\]width\[/code\] and \[code\]height\[/code\], plus \[code\]bitrate\[/code\] and \[code\]duration\[/code\] from \[code\]Video\[/code\]?Besides, is there a way to get rid of the unnecesary \[code\]Gallery\[/code\] table?I hope I made it clear enough, though, feel free to ask. Thank you in advance.UPDATE: No way. I tried to find an even simpler example not showing this behavior, but I found none.Any suggestions? Could this be a bug in Doctrine 2 or I'm missing a simpler solution?
 
Back
Top