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

Notification

Icon
Error

How to map a field to a database column
xomega
#1 Posted : Wednesday, August 1, 2012 5:43:40 PM(UTC)
xomega



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.
  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: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.
  3. Set the name attribute to specify the column name.
  4. Set the default attribute to specify the column default value or expression if needed.
  5. 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.
  6. 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.
  7. 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>
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.