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

Notification

Icon
Error

How to set up an object key
xomega
#1 Posted : Thursday, August 2, 2012 5:59:31 PM(UTC)
xomega



First thing you need to do when modeling a new object is to set up the object's key. The following guide describes how to set up a simple single field key for a primary object. For more complex scenarios you may want to read on how to work with composite keys and how to define child objects.

Here are the steps involved in defining a simple object key.
  1. First, you generally need to define a dedicated logical type in the model for the key field of your object, which you will not be able to use for any other object's key field. The only exception to this rule is when your key field needs to just reference the key of another already existing object, which typically happens either in child objects or when there is a 1-1 or 0-1 relationship between two objects.
  2. Add a field element to the fields group element of your object.
  3. Set the name attribute to the name of your key field.
  4. Set the type attribute to the dedicated type for your object key. If the key field just references another object's key then set it to the dedicated type for the referenced object's key.
  5. If the key value is auto-generated then set the key attribute to serial.
  6. If the key value is entered/supplied by the user then set the key attribute to supplied.
  7. If the key is a reference to another object's key then set the key attribute to reference.
  8. Set the required attribute to true if the key cannot be null.
  9. Provide a description of the key field in its child element doc > summary as necessary.

Below is an example that demonstrates these steps.
Code:
<module xmlns="http://www.xomega.net/omodel">
  <types>
    <type name="order number" base="integer"/>
  </types>
  <objects>
    <object name="order header">
      <fields>
        <field name="order" type="order number" key="serial" required="true">
          <doc>
            <summary>The auto-generated key of the order header.</summary>
          </doc>
        </field>
        <field name="customer" type="customer"/>
      </fields>
    </object>
    <object name="order details">
      <fields>
        <field name="order" type="order number" key="reference" required="true">
          <doc>
            <summary>A reference to the order's key.</summary>
          </doc>
        </field>
        <field name="product" type="product"/>
      </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.

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