db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Dietz <jo...@purplebear.com>
Subject Retrieving Joined Data
Date Tue, 01 Jul 2003 06:08:43 GMT
I'm having a hard time seeing the value if the Criteria addJoin method 
given that it doesn't do quite what I expected.  Let me explain by 

Let's say I have two tables, Category and Item, with a FK relationship 
where each Category has several Items (reference to the Category it 
Here's what I was hoping for, if I do this:
Criteria crit = new Criteria();
crit.addJoin(CategoryPeer.CATEGORY_ID, ItemPeer.CATEGORY_ID);
List categories = CategoryPeer.doSelect(crit);

What I was hoping for was a List of all the Categories, prefilled with 
the Items available using Category.getItems();
What in fact happens is that the list of Categories includes duplicate 
Categories, one for each item (like the resultset you would expect from 
a straight SQL Join), then a call to Category.getItems() run's another 
query to get all of the Items.

I realize I could do a ItemPeer.doSelectJoinCategory(), which would get 
me a list of all the Items with the Category prefilled, but I would 
really like to get a list of Categories with the getItems() prefilled 
(instead of running another query to get the list for each Category).

So if I don't get that with the addJoin(), then is there some other way 
to get that result?

John Dietz

View raw message