Generally, in the model first approach the column names for each object field are generated from the field name using the CamelCase, UPPER_CASE or lower_case notation as specified by the Database Case parameter of each generator or of the project's default.
In the database first approach, for the fields, where the column name generated from the field name is different from the actual column name, you can specify the explicit mapping from the field to the database column using the following steps.
- Make sure that the module element that contains your field declares a prefix for the "http://www.xomega.net/sql" namespace, e.g. xmlns:sql="http://www.xomega.net/sql"
- Add a sql:column element inside of the config element of your field definition. In the absence of such element the column name will be generated from the field name as described above.
- Set the name attribute to specify the column name.
- Set the default attribute to specify the column default value or expression if needed.
- Set the serial attribute to true, if this should be an identity column. Note that you only have to do that if you have an identity column that is not a key. Otherwise set the key attributes on the field to serial.
- If you don't want your field to be mapped to any database column, but rather use this field for temporary storing data in memory, then set the mode attribute to none.
- To validate your setup generate the database script and check the corresponding column.
Note that if you
import your model from the database, then you have an option to set up explicit mappings like that for each imported field. This will allow you to rename imported fields as you wish without worrying about the database mappings. However, the model will be much more verbose in this case.
The following snippet illustrates these steps.
Code:
<module xmlns="http://www.xomega.net/omodel"
xmlns:sql="http://www.xomega.net/sql">
<types>
<type name="order number" base="integer"/>
</types>
<objects>
<object name="order">
<fields>
<field name="order id" type="order number" key="serial" required="true"/>
<field name="customer" type="customer">
<config>
<sql:column name="CustomerID"/>
</config>
</field>
</fields>
</object>
</objects>
</module>