Re: another toMany questions

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Jul 21 2004 - 01:23:35 EDT

  • Next message: Twan Kogels: "RE: DataNode connect to socket path?"

    It's kind of Wednesday morning here too (1:00 am actually...)

    Here is how you can implement such method, providing you already have a
    hold of a Client object, and PurchaseOrder has "toClient" relationship:

    public List getOrders(Date start, Date end) {
       // substitute with whatever actual property names you have in
    PurchaseOrder...
       Expression qualifier =
         Expression.fromString("toClient = $client and startDate = $start
    and endDate = $end");
       Map params = new HashMap();
       params.put("client", this);
       params.put("start", start);
       params.put("end", end);

       SelectQuery q = new SelectQuery(PurchaseOrder.class,
    qualifier.expWithParameters(params));
       return getDataContext().performQuery(q);
    }

    You can also map the same query in the Modeler and just call it by name
    with a map of parameters in the method. Doesn't make a difference
    really...

    Note that Cayenne object layer analog of the PK/FK join in the example
    above is the part of the expression that matches on relationship:
    "toClient = $client"

    Andrus

    On Jul 20, 2004, at 8:29 PM, Gary Jarrel wrote:
    > Hi All!
    >
    > Excuse my ignorance on a Wednesday morning, but I’m looking for a
    > clean implementation for the following:
    >
    > There exists a Client object (Cayenne generated). This object has a
    > “purchaseOrderArray” which as the name implies is a toMany
    > relationship to “PurchaseOrder” (object and table). I would like to
    > create a method in Client object called getOrders(Date start, Date
    > end). Which would retrieve all orders for a particular client (an
    > instance of the Client object already exists) between certain dates.
    > Currently this logic is implemented in an Action which basically uses
    > the order_date and client_id fields in the purchase_order table. The
    > client_id field is a primary key in the client table and a foreign key
    > in the purchase_order table. I’d like to stay clear of explicitly
    > using the keys to do this operation and I would like to move most of
    > the logic into the Client object – which to me seems like a logical
    > place to put it.
    >
    > Thanks for the help
    >
    > - Gary  



    This archive was generated by hypermail 2.0.0 : Wed Jul 21 2004 - 01:23:39 EDT