2010-10-14 16 views
5

estoy usando Doctrine2 para gestionar mi modelo a continuación: Hay un concepto abstracto Content con un patrón Composite en Gallery, también un concepto abstracto Media de la que Video y Image hereda.niveles de discriminación múltiple durante el uso de Doctrine2

Mi elección fue la de añadir a discriminadores Content y Media tablas con el fin de diferenciar entre Gallery, Video y Image. Content utiliza JOIN inheritance y Media utiliza SINGLE_TABLE inheritance.

Como corro doctrine orm:schema-tool:create --dump-sql, Media la tabla está duplicando columnas del Content uno. Ese es el resultado del comando:

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 

Éstos son mis clases y anotaciones:

content.php

/** @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; 
} 

Media.php

/** @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; 
} 

gallery.php

/** @Entity */ 
class Gallery extends Content 
{ 
    /** @OneToMany(targetEntity="Content", mappedBy="container") */ 
    private $contents; 
} 

Video.php

/** @Entity */ 
class Video extends Media 
{ 
    /** @Column(type="integer") */ 
    private $bitrate; 
    /** @Column(type="integer") */ 
    private $duration; 
} 

image.php

/** @Entity */ 
class Image extends Media 
{ 
} 

pregunto: Ese es el comportamiento correcto? ¿No debería Media tener solo los campos id, width y height, más bitrate y duration de Video?

Además, ¿hay alguna manera de deshacerse de la innecesaria tabla Gallery?

Espero haber sido lo suficientemente claro, sin embargo, no dude en preguntar. Gracias de antemano.

ACTUALIZACIÓN: De ninguna manera. Intenté encontrar un ejemplo aún más simple que no mostrara este comportamiento, pero no encontré ninguno.

¿Alguna sugerencia? ¿Podría ser esto un error en Doctrine 2 o me falta una solución más simple?

Respuesta

5

Respondo a mi pregunta con la esperanza de que ayude a alguien algún día.

He abierto un bug report in github for doctrine2 con esta pregunta y la respuesta es bastante clara: Esto no es compatible.

ACTUALIZADO 2013/07/27

he intentado esto con la doctrina 2.3.4 y funciona como se esperaba.: D

+0

También estoy con la doctrina 2.3.4, pero el comportamiento no funciona. La tabla Media no se ha creado, ¿tiene algún comentario? –

+0

Puede ver mi prueba aquí: https://github.com/paulandrieux/MultipleInheritanceSandbox –

0

Si son todas abstractas me parece que tiene más sentido poner DiscriminatorMap solo en la entidad de nivel superior.

Cuestiones relacionadas