Generally, in the model first approach the table names for each object are generated from the object 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 objects, where the table name generated from the object name is different from the actual table name (e.g. the table name use plurals, while object names don't), you can specify the explicit mapping from the object to the database table 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:table element inside of the config element of your object definition. In the absence of such element the table name will be generated from the object name as described above.
- Set the name attribute to specify the table name.
- If you don't want your object to be mapped to any database table, but rather used 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 table.
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 object. This will allow you to rename imported objects as you wish without worrying about the database mappings. However, the model will be 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"/>
</fields>
<config>
<sql:table name="Orders"/>
</config>
</object>
</objects>
</module>