Balmipour
Balmipour

Reputation: 3055

Doctrine parameter to create lower-case tables?

Doctrine creates tables with names similar to the entities, using the same case. The problem is, of course, that some systems or environements have different settings, which may lead to issues between dev / stage / prod.

While we have already put lower_case_table_names=1 on our database, and changed every table mapping manually so that it is not sensitive, this isn't very handy.


So here's my question :
is there no existing way to just ask Doctrine to create tables in lower-case ?
What seems quite weird to me is that (from what I know), the standarts are to have entities/classes starting with a Capital, while databases table names should be only lower_case.

So I was expecting that the default behaviour would create lower-case tables, or at least, that a simple boolean Doctrine parameter could enable that.

We use Symfony2. Here's the mapping used for our tables (found in this SO thread)

/**
 * @Entity
 * @Table(name="something")
 */
class Something {
    [...]
}

I also read about the underscore naming strategy, but replacing camel case with underscores doesn't imply it will also remove the starting capital, does it ? (I'm not dev on the project, so I couldn't try it)

Upvotes: 3

Views: 1852

Answers (1)

lllypa
lllypa

Reputation: 233

Set preferable naming strategy: https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/namingstrategy.html#underscore-naming-strategy

In config.yml:

doctrine:
    orm:
        entity_managers:
            default:
                naming_strategy: doctrine.orm.naming_strategy.underscore

Upvotes: 7

Related Questions