Reputation: 14552
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:
Doctrine\ORM\Persisters\Entity\BasicEntityPersister#getSelectSQL(...)
the getSelectConditionSQL(...)->getSelectConditionStatementSQL(...)->getSelectConditionStatementColumnSQL(...)
is called.getSQLTableAlias(...)
with the $this->class->fieldMappings[$field]['inherited']
as $className
argument. And that is the class name of the original entity.getSQLTableAlias(...)
checks, whether the passed $className
is already in its internal list. It's not, so it sets the alias to 't' . $this->currentPersisterContext->sqlAliasCounter
(t0
) and increases the counter.BasicEntityPersister#getSelectSQL(...)
the getSelectColumnsSQL(...)->getSelectColumnSQL(...)
is called.getSQLTableAlias(...)
with the $this->className
as $className
argument. And that is the class name of the custom entity.getSQLTableAlias(...)
checks, whether the passed $className
is already in its internal list. It's not again, so it sets the alias to 't' . $this->currentPersisterContext->sqlAliasCounter
, which result now in t1
. -- And now we get this mismatch: t1
alias for the columns and t0
for the condition.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