Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-481

Incorrect table aliasing when using quoting on table names

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-BETA2
    • Component/s: Mapping Drivers, ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Doctrine trunk (r7479)

      Description

      I need to quote several table names (because of reserved words within MySQL) like so:

       
      /**
       * @Entity
       * @Table(name="`Column`")
       */
      class Column extends OptionAbstract
      

      Another entity Question is related one-to-many to these entities, however, when trying to fetch the relation I get SQL errors because it seems to use the backtick as the table alias, which is illegal. An example of the query it's generating:

      SELECT `0.id AS id1, `0.name AS name2, `0.sequence AS sequence3, `0.question_id AS question_id4 FROM `Column` `0 WHERE question_id = ?
      

        Activity

        Hide
        Menno Luiten added a comment - - edited

        Here's a patch that works for me; looping through the table name until there is a character in the range a-z (case insensitive) to use as an alias.

        Might need some more error-reporting and endless loop protection etc.

        Show
        Menno Luiten added a comment - - edited Here's a patch that works for me; looping through the table name until there is a character in the range a-z (case insensitive) to use as an alias. Might need some more error-reporting and endless loop protection etc.
        Hide
        Roman S. Borschel added a comment -

        Thanks but the problem is elsewhere. The table name should not have the quote characters. The quote characters should be stripped during metadata parsing and instead a flag quoted => true set for the table in ClassMetadata::$table. Its not hard to fix, we will look into it soon.

        Show
        Roman S. Borschel added a comment - Thanks but the problem is elsewhere. The table name should not have the quote characters. The quote characters should be stripped during metadata parsing and instead a flag quoted => true set for the table in ClassMetadata::$table. Its not hard to fix, we will look into it soon.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Menno Luiten
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: