0 votes

In ORMD1 association field names for foreign keys were generated with the casing of the entity. E.g. "MyLittleEntity_id" for an FK to MyLittleEntity.

Now it's all lowercase which is a consistency breaker. Right now I'm manually changing the field names for the sake of BC but it would be great if that was another config option.

in How To & Manuals by (3.6k points)
recategorized by

1 Answer

0 votes
Best answer

It's already configurable ;-) Unfortunately not well documented right now.

Please take a look to doctrine.ormd2.cfg.xml file. At the end of file you will see:

 <!-- #CFU - CamelCase-FirstUpper, #CFL - CamelCase-FirstLower, #UL - UnderLine -->
  <template name='association-field'>
    <field name="{inverseEntityName#UL}_{inverseFieldName#UL}"/>
  </template>
  <template name='many2many-field'>
    <field name="{inverseEntityName#UL}_{inverseFieldName#UL}" type="integer" required="true"/>
  </template>

You can configure association and many to many fields by this template. As comment explains, code after # resolves how name will be generated. So if you want to generate field names like in ORMD1, change #UL to #CFU.

As usual, you can change this settings directly in this file or overload it. One of the best improvements on new ORM Designer2 is that you can override this settings also on per-project basis.

So if you want to use original convention only in one of your project, create file project.ormd2.cfg.xml stored in directory ProjectDirectory/OrmDesigner/custom.ormd2.cfg.xml
(Note: ProjectDirectory is directory where main ORM Designer project file is located).

and insert following content to this file:

<ormd2-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <orm-configuration name="Doctrine">
    <element-templates>
      <template name='association-field'>
        <field name="{inverseEntityName#CFU}_{inverseFieldName#CFU}"/>
      </template>
      <template name='many2many-field'>
        <field name="{inverseEntityName#CFU}_{inverseFieldName#CFU}" type="integer" required="true"/>
      </template>
    </element-templates>
    </orm-configuration>
</ormd2-configuration>

Regards
L.

Note: If you're using non-standard naming convention "first_Second" name in your entities, ORM Designer convert your name to uppercase/camel case "first_second" or "firstSecond" format. If this isn't required behavior, you can update field template to this format:

<field name="{inverseEntityName}_{inverseFieldName#UL}"/>

(ommit #UL/#CFU from inverseEntityName. After that ORM Designer only copy entity name without any name conversion)

by Skipper developer (141k points)
edited by

Wow, nice! It actually works. Thanks for the docu. ;)
This could be the first article on your blog in the "How to get most of ORM Designer" series.

Regards
Jay

I know, I know ;-). I have a long list with a lot of things what should be do ;-). We're now finalizing also new web, configuring new license server, fixing all found bugs....

I hope as soon as we release it we will have a more time for blogs and articles ;-)

To clarify for anybody else that reads this:
If you want the names to be copied unchanged, just remove #UL so it just says

<field name="{inverseEntityName}_{inverseFieldName}" .../>

I almost wanted to request that feature, but it's actually pretty simple to just use no filter at all! ;)

I'm glad you like this feature ;-)