I need to extend a Doctrine Entity with single table inherit with DiscriminatorColumn and DiscriminatorMap from different values to the same subclass.
At the moment I'm trying to do of this way, but just the last value of each Entity was applying. I sought for other ways to do this, with arrays, or collections, but I found nothing in the Doctrine or Symphony Documentation. See the annotation code below:
use Doctrine\ORM\Mapping as ORM;
/**
* Classe abstrata para definição de um objeto produto
*
* @author Maycon Brito <maycon.brito@rede.bioextratus.rede>
* @package models/Doctrine/Entidades
* @subpackage Produtos
*
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="codigosubtipo", type="integer")
* @ORM\DiscriminatorMap({
* "3" = "ProdutoAcabado",
* "12" = "ProdutoMarketing",
* "34" = "ProdutoMarketing",
* "36" = "ProdutoEmbalagem",
* "46" = "ProdutoMarketing",
* "59" = "ProdutoEmbalagem",
* "60" = "ProdutoEmbalagem",
* "61" = "ProdutoEmbalagem",
* "62" = "ProdutoEmbalagem",
* "81" = "ProdutoEmbalagem",
* "82" = "ProdutoMarketing",
* "83" = "ProdutoMarketing",
* "84" = "ProdutoMarketing",
* "86" = "ProdutoMarketing",
* "87" = "ProdutoMarketing",
* "89" = "ProdutoMarketing",
* "90" = "ProdutoMarketing",
* "91" = "ProdutoMarketing",
* "92" = "ProdutoMarketing",
* "93" = "ProdutoMarketing",
* "94" = "ProdutoMarketing",
* "95" = "ProdutoMarketing",
* "96" = "ProdutoMarketing",
* "97" = "ProdutoMarketing",
* "98" = "ProdutoMarketing",
* "99" = "ProdutoMarketing",
* "100" = "ProdutoMarketing",
* "101" = "ProdutoMarketing",
* "102" = "ProdutoMarketing",
* "103" = "ProdutoEmbalagem",
* "104" = "ProdutoEmbalagem",
* "105" = "ProdutoAcabado",
* "107" = "ProdutoAcabado",
* "108" = "ProdutoEmbalagem",
* "109" = "ProdutoEmbalagem",
* "111" = "ProdutoEmbalagem",
* "112" = "ProdutoEmbalagem",
* "128" = "ProdutoEmbalagem",
* "123" = "ProdutoAcabado",
* "106" = "ProdutoMarketing",
* "110" = "ProdutoMarketing",
* "121" = "ProdutoMarketing",
* "125" = "ProdutoTerceirizado",
* "126" = "ProdutoMarketing",
* "127" = "ProdutoTerceirizado"
* })
* @ORM\Table(name="produtos", uniqueConstraints={@ORM\UniqueConstraint(name="id", columns={"id"})}, indexes={@ORM\Index(name="IDX_CodigoSubTipo", columns={"CodigoSubTipo"}), @ORM\Index(name="IDX_CodigoUnidade", columns={"CodigoUnidade"}), @ORM\Index(name="IDX_Volume", columns={"CodigoVolume"}), @ORM\Index(name="IDX_Classe", columns={"CodigoClasse"}), @ORM\Index(name="IDX_CompraAtivada", columns={"CompraAtivada"}), @ORM\Index(name="IDX_Linha", columns={"id_Linha"}), @ORM\Index(name="IDX_LinhaEnvase", columns={"id_LinhaEnvase"}), @ORM\Index(name="idx_Finalidade", columns={"Finalidade"}), @ORM\Index(name="IDX_CodigoProdutoRend", columns={"CodigoProdutoRend"})})
* @ORM\Entity
*/
abstract class Produto implements InterfaceProduto {
So by example, when I sought for all "ProdutoMarketing" entities the result was just the "ProdutoMarketing" that the value of "codigosubtipo" column was 126.
Another possible Solution:
The discriminatorcolumn (codigosubtipo) is a foreign key of another table (subtipo). This table has a column that isn't an id, but your values are determinats to define the inherited subclass above. If was possible to define the DiscrimnatorColumn of a inner join of a column of another table this problem will be solved.