Doctrine 1
  1. Doctrine 1
  2. DC-234

Doctrine_Core::generateTablesFromModels() does not work with PEAR style model class generation

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.2.0-BETA2, 1.2.0-RC1
    • Fix Version/s: None
    • Component/s: Import/Export
    • Labels:
      None
    • Environment:
      WAMP (Windows XP, Apache 2.2.11, MySQL 5.1.36, PHP 5.2.8), Doctrine 1.2.0-BETA2, Zend Framework 1.9.5

      Description

      When generating models using the following options:

      generateBaseClasses                            = TRUE
      generateTableClasses                           = FALSE
      baseClassPrefix                                = "Base_"
      baseClassesDirectory                           = 
      baseTableClassName                             = "Doctrine_Table"
      baseClassName                                  = "Default_Model_Base_Abstract"
      classPrefix                                    = "Default_Model_"
      classPrefixFiles                               = FALSE
      pearStyle                                      = TRUE

      no tables are generated in the database when calling

       Doctrine_Core::createTablesFromModels('/application/models/');

      .

        Activity

        Hide
        Jonathan H. Wage added a comment -

        This is working for me and all the tests for this functionality are passing. Make sure that before you call

        Doctrine_Core::createTablesFromModels('models');
        

        That you aren't loading/requiring any of your model classes. In order for createTablesFromModels() to know what models are in the given path it has to be able require files in the path to determine what classes are in the files.

        Show
        Jonathan H. Wage added a comment - This is working for me and all the tests for this functionality are passing. Make sure that before you call Doctrine_Core::createTablesFromModels('models'); That you aren't loading/requiring any of your model classes. In order for createTablesFromModels() to know what models are in the given path it has to be able require files in the path to determine what classes are in the files.
        Hide
        Andreas Möller added a comment -

        Got it to work.

        However, is there a way to make the names of tables created by behaviours, such as "I18n" not be prepended by the specified classPrefix? There are tables generated like

        default__model__content__translation

        , while the corresponding table is named

        content

        . It would be nice if these tables were named without using the classPrefix, and it would be nice if the desired effect could be achieved without having to specifiy the name of the table in the schema such as

        Content:
          columns:
            id:
              type: integer(4)
              primary: true
              autoincrement: true
            content_id:
              type: integer(4)
              notnull: false
            disabled:
              type: boolean
              default: false
            headline:
              type: string(64)
              notnull: false
            content:
              type: string(2000)
              notnull: false
          indexes:
            content_id:
              fields: content_id
          relations:
            Content:
              foreign: id
              local: content_id      
          actAs:
            Timestampable:
            SoftDelete:
            I18n:
              tableName: content_translation
              actAs:
                Timestampable:
                SoftDelete:
              fields: [headline, content]

        When specifying the schema for the model it isn't necessary to specify the table name either, and the table still gets generated without the classPrefix.

        With "working as before" (i.e., w/o PEAR style generation) , I meant that I wondered whether it would only be necessary to adjust code where I create instances of models directly or call methods contained, i.e.,

        $content = new Default_Model_Content();
        $something = Default_Model_Content::doSomething();
        

        instead of

        $content = new Content();
        $something = Content::doSomething();
        

        or whether it would be necessary to adjust queries using DQL, too, i.e..,

         $contentCollection = Doctrine_Query::create()->from('Default_Model_Content c')->where('c.disabled = ?')->execute(array(1));

        instead of

         $contentCollection = Doctrine_Query::create()->from('Content c')->where('c.disabled = ?')->execute(array(1));
        Show
        Andreas Möller added a comment - Got it to work. However, is there a way to make the names of tables created by behaviours, such as "I18n" not be prepended by the specified classPrefix? There are tables generated like default__model__content__translation , while the corresponding table is named content . It would be nice if these tables were named without using the classPrefix, and it would be nice if the desired effect could be achieved without having to specifiy the name of the table in the schema such as Content: columns: id: type: integer(4) primary: true autoincrement: true content_id: type: integer(4) notnull: false disabled: type: boolean default: false headline: type: string(64) notnull: false content: type: string(2000) notnull: false indexes: content_id: fields: content_id relations: Content: foreign: id local: content_id actAs: Timestampable: SoftDelete: I18n: tableName: content_translation actAs: Timestampable: SoftDelete: fields: [headline, content] When specifying the schema for the model it isn't necessary to specify the table name either, and the table still gets generated without the classPrefix. With "working as before" (i.e., w/o PEAR style generation) , I meant that I wondered whether it would only be necessary to adjust code where I create instances of models directly or call methods contained, i.e., $content = new Default_Model_Content(); $something = Default_Model_Content::doSomething(); instead of $content = new Content(); $something = Content::doSomething(); or whether it would be necessary to adjust queries using DQL, too, i.e.., $contentCollection = Doctrine_Query::create()->from('Default_Model_Content c')->where('c.disabled = ?')->execute(array(1)); instead of $contentCollection = Doctrine_Query::create()->from('Content c')->where('c.disabled = ?')->execute(array(1));
        Hide
        KONDRATEK Nicolas added a comment -

        Hi,

        I've the same problem.

        My Models are generated form Yml files, but Database isn't generated from Models.

        It's only with v.1.2, with v1.1 all is OK.

        I send an attachment, it's a small project that don't work for me...

        Show
        KONDRATEK Nicolas added a comment - Hi, I've the same problem. My Models are generated form Yml files, but Database isn't generated from Models. It's only with v.1.2, with v1.1 all is OK. I send an attachment, it's a small project that don't work for me...
        Hide
        Havelka Ondrej added a comment -

        A have got very similar problem http://www.doctrine-project.org/jira/browse/DC-344 method Doctrine_Core::createTablesFromModels('models'); realy not working.

        Show
        Havelka Ondrej added a comment - A have got very similar problem http://www.doctrine-project.org/jira/browse/DC-344 method Doctrine_Core::createTablesFromModels('models'); realy not working.
        Hide
        Andreas Möller added a comment -

        I sort of solved the issue by calling

        Doctrine_Core::createTablesFromModels();

        without specifying a model directory, while making sure the models have been loaded before.

        Show
        Andreas Möller added a comment - I sort of solved the issue by calling Doctrine_Core::createTablesFromModels(); without specifying a model directory, while making sure the models have been loaded before.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Andreas Möller
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: