Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to map an object name to a database table
xomega
#1 Posted : Wednesday, August 1, 2012 6:04:30 PM(UTC)
xomega



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.
  1. 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"
  2. 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.
  3. Set the name attribute to specify the table name.
  4. 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.
  5. 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>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Copyright © 2009-2022 Xomega.Net. All rights reserved.