mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-2606: orm:generate-proxies should generate type mappedSuperclass #3273
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Aug 9, 2013).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user xtermi:
By using the concept of mapperSuperClasses and entity classes to enable inheritance features, the proxy classes are being auto generated as expected. If i switch to production mode and try to generate all classes manually by calling the orm:generate-proxies command, the mappedSuperClasses wont be auto generated, since this type is explicitely excluded in the skipClass method.
In my opinion it is viable that the user can access either the mappedSuperClass (e.g. during a dql statement) directly or the entity class. Therefore i propose to change the skipClass method (AbstractProxyFactory.php) as shown below.
protected function skipClass(ClassMetadata $metadata)
{
/** @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo **/
return $metadata->getReflectionClass()->isAbstract();
}
If this is not as intended, this should be at least made configureable during the orm:generate-proxies command call.
@doctrinebot commented on GitHub (Aug 9, 2013):
Comment created by @ocramius:
Mapped superclasses don't need to be proxied, since the ORM won't ever have references to objects being an exact instance of a mapped superclass (not any of its subclasses). I guess they should be disabled for development mode too instead
@doctrinebot commented on GitHub (Aug 9, 2013):
Comment created by xtermi:
The ORM has references if the developer decides to use this class directly (isn't this viable?). Another example where i ran into this issue is in combination with relations and dql queries. If there's a relation e.g. book authors and their books (One-to-many).
*) Entities:
Author
EntityAuthor
Book
EntityBook
If i want to select a list of books and their authors i would use this dql statement:
SELECT b FROM EntityBook b JOIN b.author a
After querying the data i could do something like
foreach ($books as $book) {
echo $book->getAuthor()->getName();
}
The "getAuthor()" method call does simply return the mapped super class "Author" instead of "EntityAuthor", which leads to the proxy class requirement!
@0x6368656174 commented on GitHub (Apr 17, 2016):
+1
@tchule commented on GitHub (Jan 12, 2017):
+1
@Ocramius commented on GitHub (Jan 12, 2017):
Closing this as
invalid. As per discussion above, (presumably by @xtermi, unsure if same nickname here on github), there is a misunderstanding in how single table inheritance/joined table inheritance (STI/JTI) works. A mapped superclass is:Therefore there should never be instances of the superclass in a
UnitOfWork, but only instances of child classes. The same goes for proxies, and therefore the type needs to be queried somehow, before the proxy is instantiated. That is something that we're working on, but not for 2.x anyway.