Doctrine column names case sensitivity

2019-05-22 10:05发布

问题:

I'm trying to query mssql database with Doctrine. I set up connection, built schema from database and built classes. All went smoothly, but now when I try to query database:

symfony doctrine:dql "from TABLE_NAME"

I get an error Invalid column name 'column_name', because our mssql database server is setup to use CASE SENSITIVE and UPPER CASE column names, whereas doctrine is forcing all my column names to be lower case. How do I set up doctrine to either preserve sensitivity (better) or make them upper case?

回答1:

look at the link

http://www.doctrine-project.org/projects/orm/1.2/docs/manual/configuration/en

$conn->setAttribute(Doctrine_Core::ATTR_PORTABILITY,
        Doctrine_Core::PORTABILITY_FIX_CASE )


回答2:

To avoid digging up into the configuration. Use "" in your declarations. This makes the column name case-sensitive for some databases like PostgreSQL.

Example:

@ORM\JoinColumn(name="""Apples""", referencedColumnName="applies")