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

Notification

Icon
Error

How to reference an object with a composite key
xomega
#1 Posted : Sunday, August 5, 2012 5:15:37 PM(UTC)
xomega



Adding a reference to an object with a composite key in Xomega is implicit and very straightforward and is based on the Xomega's way of defining objects with composite keys. You can also read on how to reference an object with a single 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 of the object you want to reference should use a dedicated fieldset defined specifically for that object's key, which cannot be used for a key of another object. To add a reference to this object from another object you need to perform the following steps.
  1. Add a new fieldset element to the fields group element of the object that you add the reference to.
  2. Set the ref attribute of the fieldset to that dedicated fieldset of the referenced object's key. This will automatically establish a relationship between these two objects.
  3. Set the name attribute if your object may have another reference to this fieldset or have fields with the same names as the fields in the fieldset.
  4. If you want a better control over the database foreign key generated from this relationship then you can add a config > sql:composite-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 fieldset by adding the doc > summary inside the fieldset 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="invoice line item" base="integer"/>
    <type name="task" base="integer"/>
  </types>
  <fieldsets>
    <fieldset name="timesheet key">
      <field name="person" type="employee"/>
      <field name="date" type="date"/>
      <field name="task" type="task"/>
    </fieldset>
  </fieldsets>
  <objects>
    <object name="timesheet">
      <fields>
        <fieldset ref="timesheet key" key="supplied" required="true"/>
        <field name="hours" type="decimal" required="true"/>
        <field name="work description" type="memo"/>
      </fields>
    </object>
    <object name="invoice line item">
      <fields>
        <field name="item" type="invoice line item" key="serial" required="true"/>
        <fieldset ref="timesheet key" required="false">
          <config>
            <sql:composite-foreign-key name="FK_LineItem_TimeSheet" delete="no action"/>
          </config>
          <doc>
            <summary>A reference to the timesheet object with a custom foreign key configuration.</summary>
          </doc>
        </fieldset>
        <field name="amount" type="money"/>
      </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.