25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Relationships<br />

Class MyApp.Company Extends %Persistent [ClassType = persistent]<br />

{<br />

Property Name As %String;<br />

/// a Company has MANY Employees<br />

Relationship Employees As Employee [Inverse = TheCompany, Cardinality = MANY];<br />

}<br />

and Employee:<br />

class MyApp.Employee Extends %Persistent [ClassType = persistent]<br />

{<br />

Property Name As %String;<br />

Property Title As %String;<br />

/// an Employee has ONE Company<br />

Relationship TheCompany As Company [inverse = Employees, cardinality = ONE];<br />

}<br />

14.2 Dependent Relationships<br />

A dependent relationship, defined by having cardinality of PARENT on one side and CHIL-<br />

DREN on the other, has the following additional characteristics:<br />

• The existence of the child objects is dependent on the parent; if a parent object is deleted<br />

then all of its children are automatically deleted.<br />

• Once associated with a particular parent object, a child object can never be associated<br />

with a different parent. This is because the persistent ID value of the child object is based<br />

in part on the parent's persistent ID.<br />

• As much as possible, instances of child objects are clustered with parent objects on disk<br />

making disk access as optimal as possible (few page accesses are required to retrieve the<br />

children for a parent).<br />

• A dependent relationship is projected to SQL as a parent-child table.<br />

• The two classes are linked at compile time, as opposed to a ONE-MANY relationship,<br />

where the classes are compiled independently. Consequently, parent/child relationships<br />

may only be defined between two different classes. The two sides of a dependent relationship<br />

cannot be defined within a single class, or within a base class and its derived class.<br />

For example, here are the definitions for two related dependent classes, Invoice and LineItem.<br />

Invoice is:<br />

128 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>

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

Saved successfully!

Ooh no, something went wrong!