How to replace a Doctrine entity by an extending one? #11626
Unanswered
automatix
asked this question in
Support Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In my Symfony
4
app with Doctrine ORM2.7.0
I got an entityProduct
, that is part of an external package / system (Akeneo5
), I cannot just modify. Since I need to add a property (stock
) to it, I created a class, thatextends
this entity, and registered it to be used instead of the original one:src/Tpg/Bundle/AkeneoTpgBundle/Entity/Product.php
config/services/services.yml
src/Tpg/Bundle/AkeneoTpgBundle/Resources/config/doctrine/Product.orm.yml
But now I got the issue with the aliases. In the
SELECT
statement different aliases are used for the columns and the condition:Which leads to an error, of course.
The mechanism of how that happens is the following:
Doctrine\ORM\Persisters\Entity\BasicEntityPersister#getSelectSQL(...)
thegetSelectConditionSQL(...)->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(...)
thegetSelectColumnsSQL(...)->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 int1
. -- And now we get this mismatch:t1
alias for the columns andt0
for the condition.Obviously, the issue occurs in the
getSelectConditionStatementColumnSQL()
. But that place is has been staying unchanged in multiple Doctrine vesions, so that won't be a bug. What is the sense behind it?..So how to get it working correctly?
Beta Was this translation helpful? Give feedback.
All reactions