cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nishant Neeraj <nneeraj...@yahoo.com>
Subject Using Join Table
Date Thu, 10 Sep 2009 10:04:03 GMT
Hi,
I am new to ORM and Cayenne. I a pretty puzzled by relationship flattening and the way we
use Modeller to achieve this.[1]
For example, I have 4 tables. Magazines, Subscriptions, Readers and Subscription_Types.Subscription
is essentially a "join" table that makes many-to-many relationship between Readers and magazines.
Subscription_Types is a table which is used to mark each magazine and reader relationship.
(hopefully the diagram below explains this)

Magazines -------->> Subscriptions <<-------- ReadersSubscription_Types -------^^

My goal is to do this:

1. Magazine object should have List of Readers in such a way that I can get SubscriptionType
object from it. That is, 
subscriptionObject = magazineObject.getReadersList().get(i).getSubscriptionType()
2. The same way, I should be able to do similar action from Readers side. Such that If I have
a readers object I can get all associated magazines and the subscriptionType of each magazine.
-------I am a bit confused because

1. I have to join by primary key, if I want to do "to dep PK". The problem is, doing so, I
do not see any foreign-key column in dependent (Subscriptions) table. If I create explicit
foreign key columns and join using them, I can't check "to Dep PK".
2. Coming to relationship flattening. I can flatten the relationship between readers and magazines...
but the issue is, we have another dimension to it - SubscriptionType. I am not sure how to
incorporate this attribute in each reader and magazine when accessed as mentioned in the goals
above.
Since I do not see place where query is created or how flattening is done (from DB point of
view) in Cayenne, I feel a little uncomfortable with Relationship flattening.
I am going through Cayenne 2 documentations, user guide, Map.xml and a bit of source code.
Though the brevity of explanations and lack of real-world example is a bit annoying. 
I am used to DAO, VO kind of architecture; with Cayenne (or probably any ORM tool) being everything
implicit, I am going cold feet.
Any help would be appreciated. ---[1] http://cayenne.apache.org/doc12/cayennemodeler-flattened-relationships.html
Nishant


      Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message