Search code examples
sqldatabasesymfony-1.4dqldoctrine-1.2

Doctrine triple quotes sql alias


I have following sql error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a.`role`' in 'field list'

My doctrine select is

$query->select('a.role AS role');

When i look on the symfony error i see that doctrine makes the 'a.role' to a.role.

Here the full SQL Statement =

at Doctrine_Connection->execute('SELECT `a`.```role``` AS `a__0`, `a`.`role` AS `a__0` FROM `offer` `o` INNER JOIN `account` `a` *******)

Solution

  • It is best practice to not even use backticks. The only time they are necessary is when you are using tables that are reserved words, and it is suggested you don't do that in the first place.

    Turn off quoting by using the quote_identifier attribute in your databases.yml. An example of the output is referenced here.

    Example databases.yml:

    default:
      class:          sfDoctrineDatabase
        param:
          dsn: mysql:dbname=database_name;host=localhost
          username: username
          password: password
        attributes:
          quote_identifier: false
          use_native_enum: false
          validate: all
          default_table_charset: utf8
          default_table_collate: utf8_general_ci