Re: Ordering in the linked tables

From: Andrus (andru..bjectstyle.org)
Date: Sat Nov 02 2002 - 18:00:42 EST

  • Next message: Andrus Adamchik: "NHL Uses Cayenne"

    Hi Tim,

    I assume that relationship from <User> to <About> is to one? After all,
    user contains a FK to About?

    Ok, here is how to create the right query (assuming your DataMap
    ObjEntities are called User,
    About and Language), and relationships names are "about" and "language":

    ------------------------------------------
    // somehow get a hold of DataContext, e.g.
    DataContext c =
    Configuration.getSharedConfig().getDomain().createDataContext();

    // order users by About.title:
    SelectQuery q = new SelectQuery("User");
    q.addOrdering("about.title", Ordering.ASC);
    List users = c.performQuery(q);

    // Order by language title:
    SelectQuery q1 = new SelectQuery("User");
    q1.addOrdering("about.language.title", Ordering.ASC);
    List users1 = c.performQuery(q1);
    -------------------------------------------

    The main idea as you noticed, to add ordering using your map relationships
    and/or attribute names separated by ".":

    "about.title"
    "about.language.title"

    Of course these names must match the names you assigned to the
    corresponding ObjRelationships in the DataMap.

    Cheers
    Andrus

    At 03:25 AM 11/2/2002 +0500, ti..e7en.ru wrote:
    >I have three tables:
    >
    ><User>
    >id
    >name
    >about_id
    >
    ><About>
    >id
    >title
    >text
    >language_id
    >
    ><Language>
    >id
    >title
    >
    >They are linked in such order:
    >User (about_id) 1<---->M (id) About (language_id) M<---->1 (id) Langiage
    >
    >How I can receive the list of users ordered by a field "title"?
    >
    >--
    >Best regards, tim mailto:ti..e7en.ru



    This archive was generated by hypermail 2.0.0 : Sat Nov 02 2002 - 18:00:25 EST