ObjectExtender User's Guide and Reference

Creating many-to-many (M-M) relationships

The Bank sample uses a many-to-many relationship for the VapBrankBranch and the VapCurrency business objects. With the current ObjectExtender implementation, you must construct a many-to-many relationship by joining together two one-to-many relationships: VapBankBranch-to-VapBranchToCurrency and VapCurrency-to-VapBranchToCurrency. This topic explains how to create a many-to-many relationship using the ObjectExtender tools.

Do the following:

It was created as follows:

  1. Select New Association from the Associations menu.

    This launches the Association Editor.


    Figure pgs2g1 not displayed.

  2. In the Association name field, type bc to branch.
  3. Define the two Class sections.
    1. In the left Class pane, select VapBranchToCurrency.
    2. In the right Class pane, select VapBankBranch.
    3. Type branch for Role of VapBankBranch.
    4. Select Navigable.

      This means a VapBankBranch business object can be obtained from a VapBranchToCurrency business object. .

    5. Select Required. This sets a cardinality of one-to-one (1:1).
    6. Type currencyAssociations for the Role of VapBankBranch.
    7. Select Navigable.

      This means a VapAccount business object can be obtained from a VapBankBranch business object.

    8. Select Many.

      This sets a cardinality of zero-to-many (0:M). If a cardinality of one-to-many (1:M) is desired, select Required.

  4. Select OK.

Next, you define the second of the two one-to-many relationships.

Do the following:

  1. Select New Association from the Associations menu.

    This launches the Association Editor.


    Figure pgs2g2 not displayed.

  2. In the Association name field, type bc to currency.
  3. Define the two Class sections.
    1. In the left Class pane, select VapCurrency.
    2. In the right Class pane, select VapBranchToCurrency.
    3. Type branchAssociations for Role of VapBranchToCurrency.
    4. Select Navigable.

      This means a VapBankBranchToCurrency business object can be obtained from a VapCurrency business object. .

    5. Select Many. This sets a cardinality of one-to-one(1:1).
    6. Type currency for the Role of VapCurrency.
    7. Select Navigable.

      This means a VapCurrency business object can be obtained from a VapBankToCurrency business object.

    8. Select Navigable.
    9. Select Required.

      This sets a cardinality of (1:1).

  4. Select OK.

You are now done with the Model Browser. The many-to-many relationship is defined.

Next, defining this relationship using schema semantics is shown. Mapping the schema to the model will be the last step covered. These combined tasks provide the required information for creating persistence support for your business objects.

Do the following:

It was created as follows.

  1. Select Foreign Key Relationship from the Foreign_Keys menu.

    This launches the Foreign Key Relationship editor.


    Figure pgs2h1 not displayed.

  2. Type bc-branch for the Name.
  3. Type R4 for the Physical Name.
  4. If a foreign key constraint does not exist on the database, make sure Constraint exists in database is not selected.
  5. Update the Relationship section:
    1. Select BRANCH for the Primary key table.

      The Primary key column (read-only) will be updated with the primary key from the table.

    2. Select BRNCHCURR for the Foreign key table.

      In the Foreign key column, select the foreign key in the BRNCHCURR table which corresponds to the branch, BRANCH.

  6. Select OK.

Next, you will define the bc-currency side of the foreign key relationship.

Do the following:

  1. Select Foreign Key Relationship from the Foreign_Keys menu.

    This launches the Foreign Key Relationship editor.


    Figure pgs2h2 not displayed.

  2. Type bc-currency for the Name.
  3. Type R5 for the Physical Name.
  4. If a foreign key constraint does not exist on the database, make sure Constraint exists in database is not selected.
  5. Update the Relationship section:
    1. Select CURRENCY for the Primary key table

      The Primary key column (read-only) will be updated with the primary key from the table.

    2. Select BRNCHCURR for the Foreign key table.

      In the Foreign key column, select the foreign key in the BRNCHCURR table which corresponds to the currency, TYPE.

  6. Select OK.

You are now done with the Schema Browser.

The last step in defining the persistence layer for the many-to-many relationship follows.

It was created as follows.

  1. Select Bank Sample from the Datastore Maps view, VapBranchToCurrency from the Persistent Classes view, and BRNCHCURR from the Table Maps view.
  2. Select Edit Property Maps from the Table_Maps menu.

    This launches the Property Map Editor.

  3. Click the Associations tab.


    Figure pgs2i not displayed.

  4. Change the [Not Mapped] value of the branch association to bc-branch under Foreign Key Relationships.
  5. Change the [Not Mapped] value of the bc-currency association to currency under Foreign Key Relationships.
  6. Select OK.

This concludes defining the persistence layer for the many-to-many relationship.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]