Defining child objects and reference objects for a primary object
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
- In the Enterprise Explorer view, expand .
- Right-click the objectDefinitions folder and select Import. Expand General and select File system.
-
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
- Select the RecipeCommonObjectDefinition.xml definition file within this directory. Click Finish to import the file.
-
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