Re: another toMany questions

From: Mike Kienenberger (mkienen..laska.net)
Date: Wed Jul 21 2004 - 09:59:53 EDT

  • Next message: Mike Kienenberger: "Re: Invalidate lookup tables cache?"

    Gary Jarrel <garyjarre..rownbilljarrel.com.au> wrote:
    > Ahh very nice, didn't realize that I could set the client object as part
    of
    > the parameters. I'm probably not thinking hard enough!

    Hi Gary,

    You've probably already figured this out, but you'd want

    > Expression.fromString("toClient = $client and date >= $start and date
    <= $end");

    instead of

    > Expression.fromString("toClient = $client and startDate = $start and
    endDate = $end");

    -Mike

    >
    > -----Original Message-----
    > From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > Sent: Wednesday, July 21, 2004 3:24 PM
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: another toMany questions
    >
    > 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 - 09:59:37 EDT