Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-615

Single table inhertiance not working when base class is/starts-with "Module"

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA1
    • Component/s: Tools
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 10.04 LTS
      Zend Server CE 5.0
      PHP 5.3.2

      Description

      While trying to get single table inheritance working we ran into the following: Single table inheritance works fine as long as the base class that's extended isn't named "Module" or doesn't start with "Module" (e.g. ModuleBase, Moduleabcdefg). Using any other file/class name not starting with "Module" works:

      Module.php
      ========================
      <?php
      namespace App\Entities;
      
      /**
       * @Entity
       * @InheritanceType("SINGLE_TABLE")
       * @DiscriminatorColumn(name="discr", type="string")
       * @DiscriminatorMap({"module" = "Module", "blog" = "Blog"})
       */
      class Module
      {
          /** @Id @Column(type="string", length=32) */
          private $id;
          
          /** @Id @Column(type="string", length=32) */
          private $name;
      }
      
      Blog.php
      ========================
      <?php
      namespace App\Entities;
      
      /**
       * @Entity
       */
      class Blog extends Module
      {
           //...
      }
      

      Running: php ./doctrine orm:schema-tool:create results in:

      PHP Fatal error:  Class 'App\Entities\Module' not found in [path] on line [line]
      

      ... change Module.php to SystemModule.php and extend that...everythings fine.

        Activity

        Hide
        Roman S. Borschel added a comment -

        That sounds weird. Are you using Symfony (2) with Doctrine2Bundle? There is no specific treatment of classes with certain names within Doctrine that I can think of.

        Show
        Roman S. Borschel added a comment - That sounds weird. Are you using Symfony (2) with Doctrine2Bundle? There is no specific treatment of classes with certain names within Doctrine that I can think of.
        Hide
        Garrett added a comment -

        Seems weird to me to.

        I'm using the version that gets included when downloading via:

        svn co http://svn.github.com/doctrine/doctrine2.git doctrine2-orm
        

        ... not sure how to determine the exact version. Looked for some files that might indicate the version in the Symfony directory (README, Version.txt, etc.) and none exist. Did a grep and that didn't produce any results either.

        Show
        Garrett added a comment - Seems weird to me to. I'm using the version that gets included when downloading via: svn co http: //svn.github.com/doctrine/doctrine2.git doctrine2-orm ... not sure how to determine the exact version. Looked for some files that might indicate the version in the Symfony directory (README, Version.txt, etc.) and none exist. Did a grep and that didn't produce any results either.
        Hide
        Jonathan H. Wage added a comment -

        Can you check your Doctrine/ORM/Version.php file?

        Show
        Jonathan H. Wage added a comment - Can you check your Doctrine/ORM/Version.php file?
        Hide
        Jonathan H. Wage added a comment -

        Also, did you try reproducing this in a simpler scenario? i.e. without Symfony? I tried creating a simple test here and I cannot reproduce anything so far.

        Show
        Jonathan H. Wage added a comment - Also, did you try reproducing this in a simpler scenario? i.e. without Symfony? I tried creating a simple test here and I cannot reproduce anything so far.
        Hide
        Garrett added a comment -

        Can you check your Doctrine/ORM/Version.php file?
        ========================================
        Tried but that file doesn't exist for me. To make sure I was using the proper beta package I've started from scratch and downloaded Doctrine via http://www.doctrine-project.org/downloads/DoctrineORM-2.0.0-BETA1.tgz

        The only Version.php file I found was Doctrine/Common/Version.php and the "VERSION" costants value is "2.0-DEV" (That's the same version that gets spit out using "php doctrine -V")

        Also, did you try reproducing this in a simpler scenario? i.e. without Symfony?
        ============================================================
        Yes. And everything worked. I used the SchemaTool class and didn't have any issues.

        New Issues
        =========
        After starting over using the files located at the URL above the problem still exists however it's changed slightly. I still can't extend a class using another class located in a different file (same namespace). If I place both classes in the same file then the cli works. However, unlike my original post it's no longer limited to classes named "Module"; all class names fail now.

        Just to make sure I had a clean version of Symfony I grabbed the latest from http://svn.symfony-project.com/branches/2.0 (Rev 29773) and nothing changed..same error.

        Not sure if it will help but here's a stack trace:

        > php doctrine -v orm:schema-tool:update
        PHP Fatal error:  Class 'App\Entities\Module' not found in [path] on line [line]
        PHP Stack trace:
        PHP   1. {main}() /srv/www/projects/test/scripts/doctrine/doctrine:0
        PHP   2. include() /srv/www/projects/test/scripts/doctrine/doctrine:4
        PHP   3. Symfony\Components\Console\Application->run() /srv/www/projects/test/scripts/doctrine/doctrine.php:41
        PHP   4. Symfony\Components\Console\Application->doRun() /srv/www/projects/test/library/Symfony/Components/Console/Application.php:115
        PHP   5. Symfony\Components\Console\Command\Command->run() /srv/www/projects/test/library/Symfony/Components/Console/Application.php:186
        PHP   6. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /srv/www/projects/test/library/Symfony/Components/Console/Command/Command.php:152
        PHP   7. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /srv/www/projects/test/library/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53
        PHP   8. Doctrine\ORM\Mapping\Driver\AnnotationDriver->getAllClassNames() /srv/www/projects/test/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php:99
        PHP   9. require_once() /srv/www/projects/test/library/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:454
        

        ... I haven't changed the original Entities at all, they are still as described above.

        Show
        Garrett added a comment - Can you check your Doctrine/ORM/Version.php file? ======================================== Tried but that file doesn't exist for me. To make sure I was using the proper beta package I've started from scratch and downloaded Doctrine via http://www.doctrine-project.org/downloads/DoctrineORM-2.0.0-BETA1.tgz The only Version.php file I found was Doctrine/Common/Version.php and the "VERSION" costants value is "2.0-DEV" (That's the same version that gets spit out using "php doctrine -V") Also, did you try reproducing this in a simpler scenario? i.e. without Symfony? ============================================================ Yes. And everything worked. I used the SchemaTool class and didn't have any issues. New Issues ========= After starting over using the files located at the URL above the problem still exists however it's changed slightly. I still can't extend a class using another class located in a different file (same namespace). If I place both classes in the same file then the cli works. However, unlike my original post it's no longer limited to classes named "Module"; all class names fail now. Just to make sure I had a clean version of Symfony I grabbed the latest from http://svn.symfony-project.com/branches/2.0 (Rev 29773) and nothing changed..same error. Not sure if it will help but here's a stack trace: > php doctrine -v orm:schema-tool:update PHP Fatal error: Class 'App\Entities\Module' not found in [path] on line [line] PHP Stack trace: PHP 1. {main}() /srv/www/projects/test/scripts/doctrine/doctrine:0 PHP 2. include() /srv/www/projects/test/scripts/doctrine/doctrine:4 PHP 3. Symfony\Components\Console\Application->run() /srv/www/projects/test/scripts/doctrine/doctrine.php:41 PHP 4. Symfony\Components\Console\Application->doRun() /srv/www/projects/test/library/Symfony/Components/Console/Application.php:115 PHP 5. Symfony\Components\Console\Command\Command->run() /srv/www/projects/test/library/Symfony/Components/Console/Application.php:186 PHP 6. Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() /srv/www/projects/test/library/Symfony/Components/Console/Command/Command.php:152 PHP 7. Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() /srv/www/projects/test/library/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php:53 PHP 8. Doctrine\ORM\Mapping\Driver\AnnotationDriver->getAllClassNames() /srv/www/projects/test/library/Doctrine/ORM/Mapping/ClassMetadataFactory.php:99 PHP 9. require_once() /srv/www/projects/test/library/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:454 ... I haven't changed the original Entities at all, they are still as described above.
        Hide
        Garrett added a comment -

        Closing this due to my inability to reproduce on any other installation other than the original install this bug was found on.

        Show
        Garrett added a comment - Closing this due to my inability to reproduce on any other installation other than the original install this bug was found on.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Garrett
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: