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

Notification

Icon
Error

How to reuse a set of fields in multiple objects
xomega
#1 Posted : Friday, August 3, 2012 7:13:32 PM(UTC)
xomega



If you have a set of fields that appears in several objects, then Xomega allows you to define a reusable fieldset that you can use in each object. One scenario for that is when you have boilerplate fields like the user who created and last updated the record and the time stamp when it was created and last updated or to define standard address fields. Another scenario is when you want to define a composite key for an object and then reference that key in other objects.

Here are the steps required for defining and using and fieldset.
  1. Add a fieldsets element to the module element if it doesn't have one. You should add it right after the types element if one exists.
  2. Add a fieldset element to the fieldsets group element.
  3. Give the fieldset a name by setting the name attribute. The name should be unique among other fieldsets.
  4. For each field in the fieldset add a field element to the corresponding fieldset element.
  5. Set the name attribute for each field. This will be the default name of the field in each object that uses it, unless the fieldset reference has its own name specified as described below.
  6. Set the type attribute for each field. You can use Intellisense to pick a logical type defined in the model.
  7. Mark required fields by sending the required attribute for each field.
  8. Provide a fieldset description by adding a doc > summary element

To use a fieldset in an object you need to do the following.
  1. Add a fieldset element to the fields group element of your object.
  2. Set the ref attribute to the name of your fieldset. You can use Intellisense to pick the fieldset defined in the model from the list.
  3. If you have fields in your object whose name conflict with the field names from the fieldset, or if you have to reference the same fieldset more than once, then you can set the name attribute for the fieldset reference. For example, if you need to reference an address fieldset twice to specify shipping and billing addresses, and you can give each fieldset reference the corresponding name. This will prefix the field names from the fieldset with that name.
  4. You can also add nested field elements to the fieldset reference in order to override specific fields.

Here's an example of defining and using a fieldset.
Code:
<module xmlns="http://www.xomega.net/omodel">
  <types>
    <type name="order number" base="integer"/>
    <type name="user" base="string" size="8"/>
  </types>
  <fieldsets>
    <fieldset name="modification stamp">
      <field name="created by" type="user" required="true"/>
      <field name="created time" type="date time" required="true"/>
      <field name="updated by" type="user"/>
      <field name="updated time" type="date time"/>
      <doc>
        <summary>Reusable set of fields for object modification stamp.</summary>
      </doc>
    </fieldset>
  </fieldsets>
  <objects>
    <object name="order">
      <fields>
        <field name="number" type="order number" key="serial" required="true"/>
        <field name="customer" type="customer"/>
        <fieldset ref="modification stamp">
          <field name="updated by" required="true"/>
          <field name="updated time" required="true"/>
        </fieldset>
      </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.