db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brendan Miller <bmil...@dotster.com>
Subject Correct way to getRelatedObjects with each relatedObject reference to this object?
Date Thu, 12 Feb 2009 07:25:12 GMT

Maybe the subject makes sense.  Let me explain.

I have two tables, PURCHASE_ORDER and ITEM.  ITEM has a foreign key to
PRUCHASE_ORDER.  Thus, the generated BasePurchaseOrder class has a 
getItems() method that returns all the items associated with a PurchaseOrder.

I find myself with code in the Item class that needs to work with its
PurchaseOrder, so it does calls getPurchaseOrder().  The problem is that
this method loads a new copy (and a new object) from PURCHASE_ORDER.
I'd rather have a reference to the original PurchaseOrder.  Consider
this code:

    PurchaseOrder po = PurchaseOrderPeer.retrieveByPK(poid);
    for (Item item : po.getItems())

in Item.doWork():

    log.info("I'm part of order "+getPurchaseOrder().getID());

Okay, so log.info may be trivial, but you get the point--the
getPurchaseOrder() call will create a new object from the database.

Is there a way I can pre-populate the Items' aPurchaseOrder to the
object I start with (po)?

I know there are some doSelectJoinXXX methods, but they didn't look like
exactly what I wanted.  My straw-man approach is to override getItems as
in PurchaseOrder as in 

    public List<Item> getItems() throws TorqueException
        List<Item> items = super.getItems();

        for (Item item : items)

        return items;

but this seems tacky to use on every call.


To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message