cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aristedes Maniatis <>
Subject Re: Conditional relationship mapping?
Date Tue, 31 Mar 2009 10:56:55 GMT

On 29/03/2009, at 4:28 AM, Joseph Schmidt wrote:

> Is it possible for Cayenne(and the Modeler) to map conditional  
> relationships?
> I have a table, e.g. "tag" that relates to too many other tables,  
> but one row is always related only to one table. This is done by  
> having
> instead of many foreign keys columns, just with 2 in a generic way:
> - 'related_table' contains the name of the target table, and
> - 'related_row_id' is the 'id' of the row in the target table.
> I see this scenario in many schemes lately, where at least 3 or 4
> tables behave like the above "tag" table.
> Is it possible to map efficiently such a scenario with Cayenne(and  
> the modeler)? If it is, how?

Choice 1:
This looks a lot like inheritance. Explore the various options  
available to you there, particularly in Cayenne 3. This is the  
'proper' way to do it. Most of the time.

Choice 2:
Just do exactly what you are doing and fake the relationships.  
Subclass CayenneContext so that you can create the appropriate setters  
and getters to make this all work. We do this ourselves and I might be  
able to dig up some code if you get stuck.

Ari Maniatis

Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

View raw message