Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-559

Allow table name and column names to be modified by a user-supplied inflector

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.3
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None

      Description

      With the annotation mapping driver, table names default to the same as the class name, and table columns default to the same name as the field (class property) name.

      /** @Entity */
      class MyEntity // db table will by default be "MyEntity"
      {
          // ...
      
          /**
           * @Column(type="string")
           */
          protected $myProperty; // defaults to table column "myProperty" 
      }
      

      It would be great if we could override this behavior by passing in a custom inflector. So for example you could default all camelCase fields to be underscore_separated as column names in the database without needing to manually specify this in the annotations.

        Activity

        Hide
        Roman S. Borschel added a comment -

        I think Hibernate, for example, has naming strategies for this and you can implement your own custom NamingStrategy that implements a specific (default) naming convention. Maybe we want a similar approach.

        Show
        Roman S. Borschel added a comment - I think Hibernate, for example, has naming strategies for this and you can implement your own custom NamingStrategy that implements a specific (default) naming convention. Maybe we want a similar approach.
        Hide
        Christian Heinrich added a comment -

        Whats a use case for this? One could use individual table / column names via hardcoding. (@table, i guess. see manual) Is this unwanted?

        Show
        Christian Heinrich added a comment - Whats a use case for this? One could use individual table / column names via hardcoding. (@table, i guess. see manual) Is this unwanted?
        Hide
        Marc Hodgins added a comment -

        Sure there is a use case. With a large schema, hardcoding via individual @table and @column annotations is error-prone. A global "default" inflector (or naming strategy, as Roman suggests) would much cleaner. Allowing customization of "defaults" doesn't seem unreasonable to me.

        Show
        Marc Hodgins added a comment - Sure there is a use case. With a large schema, hardcoding via individual @table and @column annotations is error-prone. A global "default" inflector (or naming strategy, as Roman suggests) would much cleaner. Allowing customization of "defaults" doesn't seem unreasonable to me.
        Hide
        Benjamin Eberlei added a comment -

        This issue is referenced in Github Pull-Request GH-241
        https://github.com/doctrine/doctrine2/pull/241

        Show
        Benjamin Eberlei added a comment - This issue is referenced in Github Pull-Request GH-241 https://github.com/doctrine/doctrine2/pull/241
        Hide
        Benjamin Eberlei added a comment -

        Related Pull Request was closed: https://github.com/doctrine/doctrine2/pull/241

        Show
        Benjamin Eberlei added a comment - Related Pull Request was closed: https://github.com/doctrine/doctrine2/pull/241
        Show
        Guilherme Blanco added a comment - Fixed in https://github.com/doctrine/doctrine2/commit/abb258c951dd416fc5325ef548d15c7acd35703e

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            Marc Hodgins
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: