13.07.2015 Views

Using Caché Studio - InterSystems Documentation

Using Caché Studio - InterSystems Documentation

Using Caché Studio - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7Adding Relationships to a ClassA relationship is a special type of property that defines how two or more object instances are associatedwith each other. For example, a Company class that represents a company could have a one-to-manyrelationship with an Employee class that represents an employee (that is, each company may have oneor more employees while each employee is associated with a specific company).A relationship differs from a property in that every relationship is two-sided: for every relationshipdefinition there is a corresponding inverse relationship that defines the other side.For more information on relationships, see the Relationships chapter in <strong>Using</strong> <strong>Caché</strong> Objects.You can add a new relationship to a class definition in two ways:• Adding a relationship to the class definition using the Class Editor.• <strong>Using</strong> the New Property wizardTo add a relationship using the Class Editor, position the cursor on a blank line in the Class Editor andenter a relationship declaration:Class MyApp.Company Extends %Persistent [ClassType = persistent]{Relationship TheEmployees As Employee [cardinality=many, inverse=TheCompany];}A relationship definition must specify values for both the cardinality and inverse keywords.As this relationship has two sides, also enter the inverse relationship in the class definition of Employee:Class MyApp.Employee Extends %Persistent [ClassType = persistent]{Relationship TheCompany As Company [cardinality=one, inverse=TheEmployees];}If the two sides of the relationship do not correctly correspond to each other, there are errors whenyou try to compile.<strong>Using</strong> <strong>Caché</strong> <strong>Studio</strong> 49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!