blob: 992c30aa374a815f2f9933d03e1100fde2f6dac0 [file] [log] [blame]
Title: Flattened Relationships
<P>Flattened relationships are a fancy term for a relationship which involves three or more tables in the database. Lets say you have Artists and Exhibits. They are joined with a many-many join table called Artist_Exhibit, because many Artists could collaborate on one Exhibit and each Artist might be part of many Exhibits. Now you could map these as separate joins and end up with Java code which looks like this:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
artist.getArtistExhibits().getExhibits()
</PRE>
</DIV></DIV>
<P>but with a flattened join, it is even simpler:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
artist.getExhibits()
</PRE>
</DIV></DIV>
<P>From the application point of view there is no difference in working with flattened relationships compared to the &quot;normal&quot; ones. Cayenne internally figures out how to build the needed query joins to retrieve related objects. On adding or removing an object to/from a flattened relationship via a corresponding &quot;addTo...&quot; / &quot;removeFrom...&quot; method an appropriate join record is created or removed.</P>
<DIV class="panelMacro"><TABLE class="infoMacro"><COLGROUP><COL width="24"><COL></COLGROUP><TR><TD valign="top"><IMG src="http://cayenne.apache.org/docs/3.0/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></TD><TD><B>Flattened Relationships Limitations</B><BR>Only many-to-many flattened relatationships with a single join table can be modified. All other types of flattened relationships can be used as &quot;read-only&quot;. This is reflected in the DataObject code generated for such relationships - no set/addTo/RemoveFrom methods are created for read-only relationships.</TD></TR></TABLE></DIV>
<P>See this documentation on how to <A href="cayennemodeler-flattened-relationships.html" title="CayenneModeler Flattened Relationships">create flattened relationships in Cayenne Modeler</A></P>