DDC-2606: orm:generate-proxies should generate type mappedSuperclass #3273

Closed
opened 2026-01-22 14:17:03 +01:00 by admin · 5 comments
Owner

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.

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.
admin added the BugInvalid labels 2026-01-22 14:17:03 +01:00
admin closed this issue 2026-01-22 14:17:04 +01:00
Author
Owner

@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 @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
Author
Owner

@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!

@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!
Author
Owner

@0x6368656174 commented on GitHub (Apr 17, 2016):

+1

@0x6368656174 commented on GitHub (Apr 17, 2016): +1
Author
Owner

@tchule commented on GitHub (Jan 12, 2017):

+1

@tchule commented on GitHub (Jan 12, 2017): +1
Author
Owner

@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:

  • not referenceable in association
  • not a concrete type for the ORM

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.

@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: * not referenceable in association * not a concrete type for the ORM 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3273