Skip to content

Loading…

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

Open
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

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

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

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!

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.