with texto strip_tags remove limpiar from eliminar allow all php design-patterns doctrine2

php - texto - Múltiples niveles de discriminación al usar Doctrine2



string strip_tags (2)

Estoy usando Doctrine2 para administrar mi modelo a continuación: Hay un concepto abstracto Content con un patrón compuesto en la Gallery , también un concepto abstracto Media de los que el Video y la Image heredan.

Mi elección fue agregar discriminadores a las tablas de Content y Media para diferenciar entre Gallery , Video e Image . Content usa JOIN inheritance SINGLE_TABLE inheritance y Media usa SINGLE_TABLE inheritance .

Al ejecutar doctrine orm:schema-tool:create --dump-sql , Media table está duplicando columnas del Content . Esa es la salida 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

Aquí están 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 , además de la bitrate y la duration del Video ?

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

Espero haber dejado en claro lo suficiente, sin embargo, siéntase libre de 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?


Respondo mi pregunta yo mismo esperando que ayude a alguien algún día.

Abrí un informe de error en github para doctrine2 con esta pregunta y la respuesta es bastante clara: esto no es compatible.

ACTUALIZADO 27/07/2013

Intenté esto con Doctrine 2.3.4 y funciona como esperaba. :RE


Si son todos abstractos, creo que tiene más sentido colocar DiscriminatorMap solo en la entidad de nivel superior.