Defining child objects and reference objects for a primary object

In this lesson, you define the child object and reference object definitions for the object on which the primary object depends. You include these definitions with an object definition file.

About this task

A child object definition describes a secondary business object. A child cannot exist without a parent object. To declare that an object has child objects of a specific type, create an instance of the child object definition as a child of the parent object definition. For example, a product description is a child object of the product in the Catalogs tool.

The reference object is a special type of child object that describes a relationship between two primary objects. For example, a merchandising association is a reference object that describes a relationship between two product objects.

The Recipe primary object has three child object definitions, RecipeDescription, RecipeIngredients, and RecipeInstruction and one reference object, RecipeAssociation.

Procedure

  1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > src > xml > mycompany > recipe > objectDefinitions.
  2. Right-click the objectDefinitions folder and select Import. Expand General and select File system.
  3. Click Next, then click Browse to the following directory:

    TutorialSource\LOBTools\WebContent\WEB-INF\src\xml\mycompany\recipe\objectDefinitions, where TutorialSource is the location where you extracted the Tutorial sample source code

  4. Select the RecipeCommonObjectDefinition.xml definition file within this directory. Click Finish to import the file.
  5. Open the RecipeCommonObjectDefinition.xml files and examine the contents.
    The child objects and reference objects are defined within these files. The following code sample shows an example of a child object definition and reference object definition that are defined in a common object definition file:
    
    <Definitions>
      ...		 
    1<ChildObjectDefinition creatable="true" definitionName="cmc/recipe/RecipeIngredientsDefinition" 
      displayName="${ExtRecipeResources.ingredientsName_ColumnHeader}" displayNameProperty="ingredientName" 
      headerIcon="definingAttributeHeaderIcon" icon="definingAttributeIcon" idProperty="ingredientId" 
      newDisplayName="${ExtRecipeResources.ingredients_NewDisplayName}" objectType="RecipeIngredients" 
      openGroupTop="true" propertiesDefinition="cmc/recipe/ManageRecipeIngredients">
      <dependency localName="ExtRecipeResources" moduleName="cmc/recipe/ExtRecipeResources"/>
      <PropertyDefinition propertyName="ingredientId" type="number"/>
      <PropertyDefinition displayName="${ExtRecipeResources.ingredientsQuantity_ColumnHeader}" propertyName="amount" type="number"/>
      
      <CreateService url="/cmc/CreateRecipeIngredients">
        <ServiceParam name="storeId"/>
        <ServiceParam name="recipeId" parentProperty="true"/>            	
        <ServiceParam name="catentryId" objectPath="RecipeIngredientsReference/CatalogEntry" 
        optional="true" propertyName="catentryId" sendEmpty="false"/>
      </CreateService>	
      <UpdateService url="/cmc/UpdateRecipeIngredients">
        <ServiceParam name="storeId"/>
        <ServiceParam name="recipeId" parentProperty="true"/>
        <ServiceParam name="ingredientId" propertyName="ingredientId"/>
        <ServiceParam name="catentryId" objectPath="RecipeIngredientsReference/CatalogEntry" 
        optional="true" propertyName="catentryId" sendEmpty="false"/>          	
      </UpdateService>
      <DeleteService url="/cmc/DeleteRecipeIngredients">
        <ServiceParam name="storeId"/>
        <ServiceParam name="recipeId" parentProperty="true"/>
        <ServiceParam name="ingredientId" propertyName="ingredientId"/>
      </DeleteService>	
      
      <ChildObjectDefinition baseDefinition="cmc/recipe/RecipeIngredientsDescription"/> 
        <ReferenceObjectDefinition baseDefinition="cmc/recipe/RecipeIngredientsReference"/> 
      </ChildObjectDefinition>
      ...
      <!-- Recipe Association Definition.  -->                
    2<ReferenceObjectDefinition allowDuplicates="false" copyProtected="false" 
        definitionName="cmc/recipe/RecipeAssociationDefinition" idProperty="associationId" objectType="RecipeAssociation" 
        referencedType="Product,InheritedProduct">        
        <CreateService sendAll="false" url="/cmc/CreateRecipeAssociation"> 
          <ServiceParam name="storeId"/>
          <ServiceParam name="catentryId" objectPath="CatalogEntry" propertyName="catentryId"/>
          <ServiceParam name="recipeId" parentProperty="true"/>
        </CreateService>
        <DeleteService sendAll="false" url="/cmc/DeleteRecipeAssociation">
          <ServiceParam name="storeId"/>
          <ServiceParam name="catentryId" objectPath="CatalogEntry" propertyName="catentryId"/>
          <ServiceParam name="recipeId" parentProperty="true"/>
        </DeleteService>			
      </ReferenceObjectDefinition>  
    
    </Definitions>
    1 RecipeIngredientsDefinition
    Used as a child object of Recipe to represent the ingredient. It has three properties: name, amount, and unit of measurement. Ensure that you define the amount property explicitly, because it is a numerical type. Properties of type string do not need a definition. It has its own create, update, and delete services, which are defined in the prerequisite tutorial. It also has one child object, Ingredient description.
    2 RecipeAssociationDefinition
    The reference object definition of Recipe, which builds the reference relationship between Recipes and products. It has only create and delete services, which are defined in Tutorial: Creating a BOD service module