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
4app with Doctrine ORM2.7.0I 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, thatextendsthis entity, and registered it to be used instead of the original one:src/Tpg/Bundle/AkeneoTpgBundle/Entity/Product.phpconfig/services/services.ymlsrc/Tpg/Bundle/AkeneoTpgBundle/Resources/config/doctrine/Product.orm.ymlBut now I got the issue with the aliases. In the
SELECTstatement 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$classNameargument. And that is the class name of the original entity.getSQLTableAlias(...)checks, whether the passed$classNameis 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->classNameas$classNameargument. And that is the class name of the custom entity.getSQLTableAlias(...)checks, whether the passed$classNameis 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:t1alias for the columns andt0for 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