0 votes

When an association is created new field is automatically inserted in owner entity. Basic field properties (type, size and required flag) are automatically copied from inverse side entity primary key. However ORM properties that are specific to each framework are not copied and need to be set up. You can do it manually for every new association or set up a template that will be automatically used for all new associations and entities.

Templates

If you want to ensure that all new entities will have primary keys set as unsigned and all new associations will have the association field set as unsigned add the following templates to the ORM Designer configuration files:

<!-- primary key -->

<template element='field' use-case='create' selector='primary-field'>
    <field 
     name="id" 
     type="integer" 
     required="true" 
     unique="true" 
     primary="true" 
     auto-increment="true">
        <orm-attributes>
            <attribute name="unsigned">true</attribute>
        </orm-attributes>
    </field>    
</template>

<template element='entity' use-case='create'>
    <entity>
        <field 
         name="id" 
         type="integer" 
         size="4" 
         required="true" 
         unique="true" 
         primary="true" 
         auto-increment="true">
            <orm-attributes>
                <attribute name="unsigned">true</attribute>
            </orm-attributes>
        </field>        
    </entity>
</template>

<!-- foreign key -->

<template element='field' use-case='create' selector='association-field'>
    <field name="{entity-inverse#UL}_{field-inverse#UL}">
        <orm-attributes>
            <attribute name="unsigned">true</attribute>
        </orm-attributes> 
    </field>
</template>

<template element='field' use-case='create' selector='many-to-many-field'>
    <field 
     name="{entity-inverse#UL}_{field-inverse#UL}" 
     required="true" 
     primary="true">
        <orm-attributes>
            <attribute name="unsigned">true</attribute>
        </orm-attributes>
    </field>
</template>

Configuration files

It is best to store modified cfg files in the user configuration folder, because the changes made to the application configuration files are removed when you reinstall/update ORM Designer.

You can check our documentation to see which configuration file to use, where are they located and their loading order and how to add the templates to the configuration.

in How To & Manuals by Skipper developer (74.8k points)
edited by

Please log in or register to answer this question.