cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joseph Schmidt <joseph_schmid...@yahoo.com>
Subject Re: Conditional relationship mapping?
Date Tue, 31 Mar 2009 11:26:56 GMT

Thank you very much for your reply.
> > 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.
This would sound cool to me too, but from the Cayenne documentation example, this approach
seems to have the problem that Java has single inheritance :(.

If there's only one such table than it would work (single inheritance).
E.g. In the above example, by doing a superclass to point to the "tag" table(Tag entity),
called "Taggable". All entities that would like to have "tag"s would just need to extend the
"Taggable" entity.

The big problem is how to do it if there are more tables like that in the scheme :(.

This a very common scenario for Web2.0 apps (at least for the schemes I've seen so far) :(.

Or has this something to do with "Horizontal Inheritance"?
https://issues.apache.org/jira/browse/CAY-795

> 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.
Are there any examples about this around?

thanks,
Joseph.


      


Mime
View raw message