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

Notification

Icon
Error

How to work with composite keys
xomega
#1 Posted : Thursday, August 2, 2012 6:40:01 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 composite key for a primary object. If part of your composite key is essentially a reference to another object's key with the same field names, then you may also want to consider just making your object a child object of that other referenced object.

Here are the steps involved in defining a composite object key.
  1. First, you generally need to define a dedicated fieldset in the model for the key fields of your object, which you will not be able to use for any other object's composite key. The only exception to this rule is when your composite key 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 fieldset element to the fields group element of your object.
  3. Set the ref attribute to the dedicated fieldset for your object key. If the key fieldset just references another object's key then set it to the dedicated fieldset for the referenced object's key.
  4. If the key values are entered/supplied by the user then set the key attribute to supplied.
  5. If the key is a reference to another object's key then set the key attribute to reference.
  6. Set the required attribute to true if the key fields cannot be null.
  7. Set the name attribute if your object may have another non-key reference to this fieldset or have fields with the same names as the fields in the fieldset.
  8. Provide a description of the key fieldset in its child element doc > summary as necessary.

Below is an example that demonstrates these steps.
Code:
<module xmlns="http://www.xomega.net/omodel">
  <fieldsets>
    <fieldset name="car model key">
      <field name="make" type="string"/>
      <field name="model" type="string"/>
    </fieldset>
  </fieldsets>
  <objects>
    <object name="car model">
      <fields>
        <fieldset ref="car model key" key="supplied">
          <doc>
            <summary>Car model composite key.</summary>
          </doc>
        </fieldset>
        <field name="release year" type="integer"/>
      </fields>
    </object>
    <object name="car model details">
      <fields>
        <fieldset ref="car model key" key="reference">
          <doc>
            <summary>Car model composite key.</summary>
          </doc>
        </fieldset>
        <field name="body type" type="string"/>
        <field name="engine" type="integer"/>
      </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.