automatix
automatix

Reputation: 14552

How to replace a Doctrine entity by an extending one?

In my Symfony 4 app with Doctrine ORM 2.7.0 I got an entity Product, that is part of an external package / system (Akeneo 5), I cannot just modify. Since I need to add a property (stock) to it, I created a class, that extends this entity, and registered it to be used instead of the original one:

src/Tpg/Bundle/AkeneoTpgBundle/Entity/Product.php

<?php
namespace Tpg\Bundle\AkeneoTpgBundle\Entity;

use Akeneo\Pim\Enrichment\Component\Product\Model\Product as AkeneoProduct;

class Product extends AkeneoProduct
{
    private $stock;

    // access methods ...
}

config/services/services.yml

parameters:
  pim_catalog.entity.product.class: 'Tpg\Bundle\AkeneoTpgBundle\Entity\Product'

src/Tpg/Bundle/AkeneoTpgBundle/Resources/config/doctrine/Product.orm.yml

Tpg\Bundle\AkeneoTpgBundle\Entity\Product:
  type: entity
  table: pim_catalog_product
  fields:
    stock:
      type: integer
      nullable: false

But now I got the issue with the aliases. In the SELECT statement, different aliases are used for the columns and the condition:

SELECT 
    t1.id AS id_2,
    t1.is_enabled AS is_enabled_3,
    ...
FROM pim_catalog_product t1 
WHERE t0.id = 1207

Which leads to an error, of course.

The mechanism of how that happens is the following:

Obviously, the issue occurs in the getSelectConditionStatementColumnSQL(). But that place has stayed unchanged in multiple Doctrine versions, so that won't be a bug. What is the sense behind it?..

How to get it working correctly?

Upvotes: 0

Views: 127

Answers (0)

Related Questions