Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2693

Attribute/association overrides should be ignored when generating entities

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor 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

          Joris van de Sande created issue -
          Hide
          Rein Baarsma added a comment - - edited

          I have the same issue and it's easy to reproduce with a clean Symfony 2 setup with FOSUserBundle.
          Once you add

           * @ORM\AttributeOverrides({
           *      @ORM\AttributeOverride(name="usernameCanonical",
           *          column=@ORM\Column(
           *              name     = "username_canonical",
           *              type     = "string",
           *              length   = 255,
           *              unique   = false
           *          )
           *      )
           * })
          

          It will properly do doc:schema:update --force
          But it will fail on doc:gen:entities (YourEntity)

          Show
          Rein Baarsma added a comment - - edited I have the same issue and it's easy to reproduce with a clean Symfony 2 setup with FOSUserBundle. Once you add * @ORM\AttributeOverrides({ * @ORM\AttributeOverride(name= "usernameCanonical" , * column=@ORM\Column( * name = "username_canonical" , * type = "string" , * length = 255, * unique = false * ) * ) * }) It will properly do doc:schema:update --force But it will fail on doc:gen:entities (YourEntity)
          Marco Pivetta made changes -
          Field Original Value New Value
          Priority Major [ 3 ] Minor [ 4 ]
          Marco Pivetta made changes -
          Link This issue is duplicated by DDC-3109 [ DDC-3109 ]
          Hide
          Andy Waterman added a comment -

          Not sure I agree this is minor - might not affect many users, but it's pretty blocking if you do run into it. Any ideas on a fix?

          Show
          Andy Waterman added a comment - Not sure I agree this is minor - might not affect many users, but it's pretty blocking if you do run into it. Any ideas on a fix?
          Hide
          Marco Pivetta added a comment -

          Andy Waterman you are supposed to manually edit generated entities anyway

          Show
          Marco Pivetta added a comment - Andy Waterman you are supposed to manually edit generated entities anyway
          Hide
          Andy Waterman added a comment -

          " you are supposed to manually edit generated entities anyway"

          This applies to creating new entities as well as adapting old ones. Ie. Once you use an AttributeOverride anywhere in your project, you then cannot use generate:entities anywhere else.

          Show
          Andy Waterman added a comment - " you are supposed to manually edit generated entities anyway" This applies to creating new entities as well as adapting old ones. Ie. Once you use an AttributeOverride anywhere in your project, you then cannot use generate:entities anywhere else.
          Hide
          Marco Pivetta added a comment -

          Andy Waterman yes, and you are supposed to avoid the generator after the first run.

          Show
          Marco Pivetta added a comment - Andy Waterman yes, and you are supposed to avoid the generator after the first run.
          Hide
          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
          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
          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
          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
          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
          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
          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
          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);

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2693, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Joris van de Sande
            • Votes:
              8 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated: