DDC-1006: Entity Generator Regenerate If Not New #1252

Closed
opened 2026-01-22 13:07:15 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 31, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user sw45859:

When regenerating entities from xml ( and i am sure all others ) it gives a blank entity class when the file exists and the regenerateIfExists is set to true, the expected result would be a full entity with any removed columns removed from the entity and new columns to be added.

i've come up with a fix that i assume is the correct way
i haven't tested this without the regeneration set to true since my application requires the regeneration, here's my code block i'm using:

$em->getConfiguration()->setMetadataDriverImpl(
new \Doctrine\ORM\Mapping\Driver\SesXmlDriver(
'ext/Doctrine/Entities/xml_metadata/'
)
);

$cmf = new Doctrine\ORM\Tools\DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();

$generator = new \Doctrine\ORM\Tools\EntityGenerator();
$generator->setGenerateAnnotations(true);
$generator->setGenerateStubMethods(true);
$generator->setRegenerateEntityIfExists(true);
//$generator->setUpdateEntityIfExists(true);
$generator->generate($metadata, 'ext/');

in the *hasProperty and *hasMethod functions, need to add the below to the inline check:

|| ( ! $this->_isNew && $this->_regenerateEntityIfExists)

Originally created by @doctrinebot on GitHub (Jan 31, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user sw45859: When regenerating entities from xml ( and i am sure all others ) it gives a blank entity class when the file exists and the regenerateIfExists is set to true, the expected result would be a full entity with any removed columns removed from the entity and new columns to be added. i've come up with a fix that i assume is the correct way i haven't tested this without the regeneration set to true since my application requires the regeneration, here's my code block i'm using: $em->getConfiguration()->setMetadataDriverImpl( new \Doctrine\ORM\Mapping\Driver\SesXmlDriver( 'ext/Doctrine/Entities/xml_metadata/' ) ); $cmf = new Doctrine\ORM\Tools\DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); $metadata = $cmf->getAllMetadata(); $generator = new \Doctrine\ORM\Tools\EntityGenerator(); $generator->setGenerateAnnotations(true); $generator->setGenerateStubMethods(true); $generator->setRegenerateEntityIfExists(true); //$generator->setUpdateEntityIfExists(true); $generator->generate($metadata, 'ext/'); in the *hasProperty and *hasMethod functions, need to add the below to the inline check: || ( ! $this->_isNew && $this->_regenerateEntityIfExists)
admin added the Bug label 2026-01-22 13:07:15 +01:00
admin closed this issue 2026-01-22 13:07:15 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2011):

Comment created by @beberlei:

blank as in the file is completly empty?

@doctrinebot commented on GitHub (Feb 2, 2011): Comment created by @beberlei: blank as in the file is completly empty?
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2011):

Comment created by sw45859:

no, it generates just the class with no properties or methods.

@doctrinebot commented on GitHub (Feb 2, 2011): Comment created by sw45859: no, it generates just the class with no properties or methods.
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2011):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Feb 2, 2011): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Feb 2, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 2, 2011): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1252