Doctrine 1
  1. Doctrine 1
  2. DC-295

Export_Schema does not properly account for classes that have a prefix.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.0-BETA3, 1.2.0-RC1
    • Fix Version/s: 1.2.0
    • Component/s: None
    • Labels:
      None

      Description

      When trying to run doctrine-cli generate-yaml-models (I think other tasks are affected too), I get a yaml file consisting of { }.
      I think this is because on line 48 of Doctrine/Export/Schema.php $classPrefix is not passed to Doctrine_Core::loadModels($directory) even if it is set in the configuration array.
      This is causing doctrine to think there are no models to generate the yaml for if I am using the $classPrefix.

      I'm just learning Doctrine so it's entirely possibly something else is to blame for my issue, but this is where I was able to trace it to.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        I fixed an issue similar to this last week. Make sure you're all fully up-to-date from the 1.2 branch and let me know if the problem still persists there.

        Thanks, Jon

        Show
        Jonathan H. Wage added a comment - I fixed an issue similar to this last week. Make sure you're all fully up-to-date from the 1.2 branch and let me know if the problem still persists there. Thanks, Jon
        Hide
        Matthew Miller added a comment -

        I did an svn checkout from here http://svn.doctrine-project.org/branches/1.2/ and the behavior appears to be the same.

        Show
        Matthew Miller added a comment - I did an svn checkout from here http://svn.doctrine-project.org/branches/1.2/ and the behavior appears to be the same.
        Hide
        Jonathan H. Wage added a comment -

        I added an attribute for setting the class prefix:

        $manager->setAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX, 'MyPrefix_');
        

        Later we can make use of this attribute in more places possibly.

        Show
        Jonathan H. Wage added a comment - I added an attribute for setting the class prefix: $manager->setAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX, 'MyPrefix_'); Later we can make use of this attribute in more places possibly.
        Hide
        Matthew Miller added a comment -

        I'll do some more testing to get a better idea of what's going on but here's what I've got so far.

        line 627 of Core.php in the loadModelsfunction you have:

        $classPrefix = $classPrefix === null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX) : null;

        Shouldn't the final null be $classPrefix? Otherwise I think you're overwriting a prefix that was passed as a parameter to the function.

        When generating the models from the DB I pass options to the Doctrine_Cli that look something like:

        $options['generate_models_options'] = array(
            'pearStyle' => true,
            'generateTableClasses' => true,
            'classPrefix' => 'Model_',
            'baseClassPrefix' => 'Base_',
            'baseClassesDirectory' => 'Base',
            'classPrefixFiles' => false,
            'generateAccessors' => false,
        );

        Would it make sense to use these or similar for generating the yaml from the models?

        My initial test got me a little further but now it's having trouble loading the Base classes. It looks like this has to do with the baseClassPrefix and baseClassesDirectory but I'll test it more later.

        Show
        Matthew Miller added a comment - I'll do some more testing to get a better idea of what's going on but here's what I've got so far. line 627 of Core.php in the loadModelsfunction you have: $classPrefix = $classPrefix === null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX) : null ; Shouldn't the final null be $classPrefix? Otherwise I think you're overwriting a prefix that was passed as a parameter to the function. When generating the models from the DB I pass options to the Doctrine_Cli that look something like: $options['generate_models_options'] = array( 'pearStyle' => true , 'generateTableClasses' => true , 'classPrefix' => 'Model_', 'baseClassPrefix' => 'Base_', 'baseClassesDirectory' => 'Base', 'classPrefixFiles' => false , 'generateAccessors' => false , ); Would it make sense to use these or similar for generating the yaml from the models? My initial test got me a little further but now it's having trouble loading the Base classes. It looks like this has to do with the baseClassPrefix and baseClassesDirectory but I'll test it more later.
        Hide
        Jonathan H. Wage added a comment -

        Yes you are right, the line was wrong and the null should have been $classPrefix. As for the options, I am not sure. You will just need to play with different combinations until it works. Make sure that the class name and path to the file with the class in it are the same. That is how it is able to autoload the model classes.

        Show
        Jonathan H. Wage added a comment - Yes you are right, the line was wrong and the null should have been $classPrefix. As for the options, I am not sure. You will just need to play with different combinations until it works. Make sure that the class name and path to the file with the class in it are the same. That is how it is able to autoload the model classes.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: