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

Notification

Icon
Error

How to establish a relationship between objects
xomega
#1 Posted : Sunday, August 5, 2012 4:16:34 PM(UTC)
xomega



Defining a relationship between objects in Xomega is implicit and very straightforward and is based on the Xomega's way of defining object keys. This guide describes a simple case where you need to reference an object with a single key field. You can also read on how to reference an object with a composite key separately. Note, that there is also an implicit relationship between a child object and its parent object, which you can also learn about by reading on how to define child objects.

The key field of the object you want to reference should use a dedicated logical type defined specifically for that object's key. It cannot be used for any key field of another object. To add a reference to this object from another object you need to perform the following steps.
  1. Add a new field element to the fields group element of the object that you add the reference to.
  2. Specify field name by setting the name attribute.
  3. Set the type attribute of the field to the dedicated logical type of the referenced object's key field. This will automatically establish a relationship between these two objects. You can also set it to any subtype of such logical type as long as this subtype or any of its parent types are not used as a key for another object.
  4. If you want a better control over the database foreign key generated from this relationship then you can add a config > sql:foreign-key child element to the field element, where the sql prefix should map to the namespace http://www.xomega.net/sql.
  5. If you want to override the name of the foreign key generated for the database, then you can set the name attribute accordingly.
  6. If you want to override the update or delete actions, then you can set the corresponding attributes as appropriate.
  7. You can also specify to NOT generate the foreign key by setting the mode attribute to none.
  8. Specify the description of the field by adding the doc > summary inside the field element.

Below is an example that illustrates this approach.
Code:
<module xmlns="http://www.xomega.net/omodel"
        xmlns:sql="http://www.xomega.net/sql">
  <types>
    <type name="customer account" base="integer"/>
    <type name="customer name" base="string" size="50"/>
    <type name="order number" base="integer"/>
  </types>
  <objects>
    <object name="customer account">
      <fields>
        <field name="number" type="customer account" key="serial"/>
        <field name="name" type="customer name"/>
      </fields>
    </object>
    <object name="order">
      <fields>
        <field name="number" type="order number" key="serial" required="true"/>
        <field name="customer" type="customer account">
          <config>
            <sql:foreign-key name="fk_order_customer" update="cascade" delete="no action"/>
          </config>
          <doc>
            <summary>A reference to the customer account object with a custom foreign key configuration.</summary>
          </doc>
        </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.