Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2693

Attribute/association overrides should be ignored when generating entities

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.4, 2.3.4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:

      Description

      The "orm:generate-entities" command fails when doctrine attribute and/or association overrides are used. So from the moment that you use an attribute/association override, it is implossible to use the generate entities command. I think that the solution to this problem is to ignore the overrides when generating entities.

      The exception given in case of an attribute override is (this is executed within a Symfony2 project doctrine:generate:entities):

      Generating entity "My\AppBundle\Entity\Job"
      
        [Doctrine\ORM\Mapping\MappingException]
        Invalid field override named 'value' for class 'My\AppBundle\Entity\Job'.
      
      Exception trace:
       () at /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:89
       Doctrine\ORM\Mapping\MappingException::invalidOverrideFieldName() at /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:1922
       Doctrine\ORM\Mapping\ClassMetadataInfo->setAttributeOverride() at /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php:564
       Doctrine\ORM\Mapping\Driver\YamlDriver->loadMetadataForClass() at /path/to/project/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:104
       Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass() at /path/to/project/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:113
       Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /path/to/project/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:302
       Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /path/to/project/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:212
       Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /path/to/project/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:112
       Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at /path/to/project/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:196
       Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getAllMetadata() at /path/to/project/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:176
       Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getMetadataForClass() at /path/to/project/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Mapping/MetadataFactory.php:76
       Doctrine\Bundle\DoctrineBundle\Mapping\MetadataFactory->getClassMetadata() at /path/to/project/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php:106
       Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() at /path/to/project/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:242
       Symfony\Component\Console\Command\Command->run() at /path/to/project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:200
       Symfony\Component\Console\Application->doRun() at /path/to/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:83
       Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /path/to/project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:106
       Symfony\Component\Console\Application->run() at /path/to/project/app/console:19
      

        Issue Links

          Activity

          Hide
          waterman Andy Waterman added a comment -

          You really cannot use the generate:entities command to generate method stubs in ANY of your entities or new entities after the first time you run it??

          If this use case works as designed without AttributeOverride in the project, but not with AttributeOverrides, then it's a bug not us doing it wrong.

          Show
          waterman Andy Waterman added a comment - You really cannot use the generate:entities command to generate method stubs in ANY of your entities or new entities after the first time you run it?? If this use case works as designed without AttributeOverride in the project, but not with AttributeOverrides, then it's a bug not us doing it wrong.
          Hide
          cmodijk Cliff Odijk added a comment - - edited

          I agree with Andy Waterman that this is a bug if it works al the time and not when you use AttributeOverrides.

          Now we just temporary remove the AttributeOverrides and then generate our stubs.

          Show
          cmodijk Cliff Odijk added a comment - - edited I agree with Andy Waterman that this is a bug if it works al the time and not when you use AttributeOverrides. Now we just temporary remove the AttributeOverrides and then generate our stubs.
          Hide
          cmodijk Cliff Odijk added a comment - - edited

          I tried to debug the issue and found that during the gatering of the class metadata you will get the DisconnectedClassMetadataFactory which gives the StaticReflectionService for the getParentClasses it returns an empty array which should be al the parent classes of an entity. Because of this the mapping information of the parent class does not exists and can't be overwritten.

          Show
          cmodijk Cliff Odijk added a comment - - edited I tried to debug the issue and found that during the gatering of the class metadata you will get the DisconnectedClassMetadataFactory which gives the StaticReflectionService for the getParentClasses it returns an empty array which should be al the parent classes of an entity. Because of this the mapping information of the parent class does not exists and can't be overwritten.
          Hide
          cmodijk Cliff Odijk added a comment -

          If I implement the following code in the getParentClasses of the StaticReflectionService it work's like a charm

          if ( ! class_exists($class)) {
                      throw MappingException::nonExistingClass($class);
                  }
          
                  return class_parents($class);
          
          Show
          cmodijk Cliff Odijk added a comment - If I implement the following code in the getParentClasses of the StaticReflectionService it work's like a charm if ( ! class_exists($class)) { throw MappingException::nonExistingClass($class); } return class_parents($class);
          Hide
          eschultz Enrico Schultz added a comment -

          This bug has been fixed by fixing DDC-1379. If you use protected variables in your base class, the schema is created correctly and the entity generator also does not generate properties twice. When using Symfony2, just set "doctrine/orm" to "2.4@dev" in "composer.json" or wait for an upcoming release.

          Show
          eschultz Enrico Schultz added a comment - This bug has been fixed by fixing DDC-1379 . If you use protected variables in your base class, the schema is created correctly and the entity generator also does not generate properties twice. When using Symfony2, just set "doctrine/orm" to "2.4@dev" in "composer.json" or wait for an upcoming release.

            People

            • Assignee:
              beberlei Benjamin Eberlei
              Reporter:
              jvandesande Joris van de Sande
            • Votes:
              9 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

              • Created:
                Updated: