When we added addresses to the application, we added a simple property, Home
, of type Address
. We are going to do something somewhat different for phone numbers. We are going to create a relationship between the Contact
More specifically, we are going to create a Parent-Child
relationship with Contact
as the parent and PhoneNumber
as the child. The effect of this will be that each contact can contain several phone numbers while each phone number must be contained by a single contact. Moreover, deleting a contact automatically deletes all of the phone numbers that it contains.
When you create a parent-child
relationship between a pair of classes, you add a new property to each of the classes. To the parent class, you add a collection of objects of the child class type. To the child class, you add a property that refers back to the parent class object.
Here are the steps for creating the relationship using the Add Property
wizard. Note that you can also code the relationship by hand in the class editor if you prefer.
in Studio and launch the Add Property
wizard. To launch the wizard, click
(Same as before). On the Wizard's first screen assign the property the name PhoneNumbers
Relationship PhoneNumbers As ContactDB.PhoneNumber
[ Cardinality = children, Inverse = Contact ];
Relationship Contact As ContactDB.Contact
[ Cardinality = parent, Inverse = PhoneNumbers ];
© 1997-2019 InterSystems Corporation, Cambridge, MA