blob: 8154bdbfd7f38b101520ae10ef808481f3580016 [file] [log] [blame]
Title: CayenneModeler Flattened Relationships
<H3><A name="CayenneModelerFlattenedRelationships-FlattenedRelationships"></A>Flattened Relationships</H3>
<P>ObjRelationships that map to more than a single DbRelationship are called <TT>&quot;flattened&quot;</TT>.</P>
<P>The most common case for using flattened relationships is modeling many-to-many relationships with a join table. E.g. ARTIST DbEntity has to-many relationship to ARTIST_EXHIBIT; ARTIST_EXHIBIT in turn has a to-one relationship to EXHIBIT DbEntity. We can create a single ObjRelationship from Artist ObjEntity to Exhibit ObjEntity that spawns two DbRelationships. This will be a to-many relationship. Lets say it is called &quot;exhibitArray&quot;. Generated class file for Artist would contain a getExhibitArray() method returning a list of Exhibits for a given artist instance. An obvious advantage of having a flattened relationship in this case is to avoid mapping a join table as an object, meaningless in the context of the object model.</P>
<P>Flattened relationships work across any combination of to-one and to-many DbRelationships. If all the relationships are to-one, then the resulting flattened relationship is also to-one. If there is at least one to-many, the result is to-many as well.</P>
<DIV class="panelMacro"><TABLE class="noteMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cayenne.apache.org/docs/3.0/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B>Read-Only Note</B><BR>Most of flattened relationships are treated as read-only by Cayenne. Only one (the most commonly used) type is read/write. It is many-to-many (n:m) flattened relationships with a single join table.</TD></TR></TABLE></DIV>
<P>To map an ObjRelationship to a chain of DbRelationships, select ObjRelationship table row and click &quot;Edit Relationship&quot; button in the bottom right. &quot;ObjRelationship Inspector&quot; dialog will appear. The dialog contains a DbRelationship navigator, allowing to map regular as well as flattened relationships:</P>
<P><SPAN class="image-wrap" style=""><IMG src="cayennemodeler-flattened-relationships.data/modeler-flattenedrelationship.png" style="border: 0px solid black"></SPAN></P>
<DIV class="panelMacro"><TABLE class="noteMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cayenne.apache.org/docs/3.0/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B>Join Table Tip</B><BR>If you flatten across a join table and this join table was mapped to an ObjEntity (and a correspoding Java class), such ObjEntity can be deleted, as it is no longer needed. Underlying DbEntity must be preserved.</TD></TR></TABLE></DIV>
<P>Further information about flattened relationships can be <A href="flattened-relationships.html" title="Flattened Relationships">found here</A>.</P>