Re: Using Join Table

From: Nishant Neeraj (nneeraj12..ahoo.com)
Date: Thu Sep 10 2009 - 06:23:48 EDT

  • Next message: gilbertoca: "Re: [Modeler] DbEntity:Primery Key:PK Generation Strategy - Is there any option for natural primary key?"

    I am sorry all the formatting messed up.Here is the link to DB model image http://i30.tinypic.com/jaz4wm.jpg
    Image: http://i30.tinypic.com/jaz4wm.jpg
    - Nishant

    --- On Thu, 10/9/09, Nishant Neeraj <nneeraj12..ahoo.com> wrote:

    From: Nishant Neeraj <nneeraj12..ahoo.com>
    Subject: Using Join Table
    To: use..ayenne.apache.org
    Date: Thursday, 10 September, 2009, 3:34 PM

    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 See the Web&#39;s breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/



    This archive was generated by hypermail 2.0.0 : Thu Sep 10 2009 - 06:24:27 EDT