Doctrine 1
  1. Doctrine 1
  2. DC-173

Error generating models from db when a table name is a reserved word in PostgreSQL

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.2.0-ALPHA3
    • Fix Version/s: 1.2.0-BETA1
    • Component/s: None
    • Labels:
      None
    • Environment:
      PostgreSQL 8.1, PHP 5.2

      Description

      I'm getting an exception when generating models from db because I have a table named 'role' which is a reserved word, as you can see at http://www.postgresql.org/docs/8.1/static/sql-keywords-appendix.html

      I have a table named 'role_permission' which has a foreign key pointing to table 'role'. When Doctrine tries to find the related tables using 'Doctrine_Import_Pgsql::listTableRelations()', the executed SQL returns:
      FOREIGN KEY (role_id) REFERENCES "role"(role_id) ON DELETE CASCADE
      with the table name role quoted as it is a reserved word.

      My workaround is to change Doctrine_Import_Pgsql line 281 from:

      $relations[] = array('table' => $values[2],

      to:

      $relations[] = array('table' => (strpos($values[2],'"') === 0)?substr($values[2],1,-1):$values[2],

        Activity

        Hide
        Jonathan H. Wage added a comment -

        This was already fixed last night.

        Show
        Jonathan H. Wage added a comment - This was already fixed last night.
        Hide
        Andreas Möller added a comment -

        I have a similar issue when attempting to generate SQL from models previously generated from Yaml schema files.

        When defining a schema as

        Resource:
        columns:
        id:
        type: integer(4)
        autoincrement: true
        primary: true

        an exception is thrown with the message 'no valid table name specified'. When adding a tablename to the schema

        Resource:
        tableName: resourcexx

        the problem persists.

        I believe I did not have this problem a couple of updates from the SVN ago, will track it down and maybe open a ticket. I am using Doctrine 1.2.0-ALPHA3.

        Show
        Andreas Möller added a comment - I have a similar issue when attempting to generate SQL from models previously generated from Yaml schema files. When defining a schema as Resource: columns: id: type: integer(4) autoincrement: true primary: true an exception is thrown with the message 'no valid table name specified'. When adding a tablename to the schema Resource: tableName: resourcexx the problem persists. I believe I did not have this problem a couple of updates from the SVN ago, will track it down and maybe open a ticket. I am using Doctrine 1.2.0-ALPHA3.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Antonio J. Garcia Lagar
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: