Doctrine 1
  1. Doctrine 1
  2. DC-457

Generating YAML schema from DB breaks on certain table names

    Details

    • Type: Improvement Improvement
    • Status: Reopened
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: Import/Export
    • Labels:
      None
    • Environment:
      Linux, Symfony 1.4.1, Doctrine 1.2.1

      Description

      When attempting to reverse engineer databases using the generate-yaml-db task (via Symfony's doctrine:build-schema task), I've run into some issues due to table names not being compatible with PHP classnames. It creates the PHP classes in /tmp, setting the class name to the same as the table name, and then attempts to build the YAML files off of those.

      I attempted to do this a few months ago and ran into issues because some of the table names began with numbers ("123MyTable" is not a valid PHP class name). My most recent attempt failed because of a table named "List", which is a reserved PHP keyword.

      While I'm not sure if this is the ideal solution, I think allowing a way to pre-define a prefix for the generated PHP class names would be great.

        Activity

        Hide
        Stefan added a comment -

        I think there seems to be a general problem in usage of table names, when using the generating from database to yml.

        I think there something changed with the naming stragegies in the last versions (I do not know in wich one), but it works with doctrine 1.0.10 (used in symfony 1.2.8).

        theoretical stragegies:
        1. Only the first letter is a capital (e.g. ProjectCategory --> Projectcategory)
        2. When a _ is inside the name, the _ is removed an a capital will used (e.g. Project_Values --> ProjectValues)

        But doctrine does not make use of this anymore. When I generate with doctrine 1.2.1 (used in symfony 1.3.2) my table ProjectCategory will be named as ProjectCategory in schema. And when the schema is wrong, all generated models are incompatible to older versions.

        Show
        Stefan added a comment - I think there seems to be a general problem in usage of table names, when using the generating from database to yml. I think there something changed with the naming stragegies in the last versions (I do not know in wich one), but it works with doctrine 1.0.10 (used in symfony 1.2.8). theoretical stragegies: 1. Only the first letter is a capital (e.g. ProjectCategory --> Projectcategory) 2. When a _ is inside the name, the _ is removed an a capital will used (e.g. Project_Values --> ProjectValues) But doctrine does not make use of this anymore. When I generate with doctrine 1.2.1 (used in symfony 1.3.2) my table ProjectCategory will be named as ProjectCategory in schema. And when the schema is wrong, all generated models are incompatible to older versions.
        Hide
        Jonathan H. Wage added a comment -

        Hmm. I don't quite understand. I tested the things you described and it all works as I expected it to. You'll have to provide some more information.

        Show
        Jonathan H. Wage added a comment - Hmm. I don't quite understand. I tested the things you described and it all works as I expected it to. You'll have to provide some more information.
        Hide
        Ari Pringle added a comment -

        Sorry for the delay in response.

        Here's how to reproduce my original issue (I should also mention that I'm running PHP 5.2.4):

        mysql> create table List (id int not null auto_increment,primary key(id));
        
        bash$ ./symfony doctrine:build-schema
        >> doctrine  generating yaml schema from database
        
        Parse error: syntax error, unexpected T_LIST, expecting T_STRING in /tmp/tmp_doctrine_models/List.php on line 17
        
        bash$ sed -n '17p' /tmp/tmp_doctrine_models/List.php 
        class List extends Doctrine_Record
        

        The same thing happens if the table name begins with a number (ie 123MyTable).

        Again, I'm not sure if this is the ideal solution, but being able to define a prefix to the generated class names would take care of this issue (so the generated class name above could be MyPrefix_List instead of List)

        Show
        Ari Pringle added a comment - Sorry for the delay in response. Here's how to reproduce my original issue (I should also mention that I'm running PHP 5.2.4): mysql> create table List (id int not null auto_increment,primary key(id)); bash$ ./symfony doctrine:build-schema >> doctrine generating yaml schema from database Parse error: syntax error, unexpected T_LIST, expecting T_STRING in /tmp/tmp_doctrine_models/List.php on line 17 bash$ sed -n '17p' /tmp/tmp_doctrine_models/List.php class List extends Doctrine_Record The same thing happens if the table name begins with a number (ie 123MyTable). Again, I'm not sure if this is the ideal solution, but being able to define a prefix to the generated class names would take care of this issue (so the generated class name above could be MyPrefix_List instead of List)

          People

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

            Dates

            • Created:
              Updated: