Re: Standalone prefetch without main query?

Jonathan Rochkind <[email protected]>
Newsgroups gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
Good point about the to-many; I hadn't thought about that.

At 09:10 AM 11/5/2002 +0000, John Pollard wrote:
>Your solution 2 is very close to what I need, I now see that 
>petite_abeille posted some similar info a while ago. The problem is that 
>it can't cope with second level relationships. When using 
>setPrefetchingRelationshipKeyPaths() on a fetch spec it is possible and in 
>my case necessary to set more than one keypath and to include a second 
>level relationship, for example "stockItems" and 
>"stockItems.stockByLocations". The batchFetchRelationship() method fails 
>if given a keypath deeper than 1 rather than the simple relationship name. 
>The fetch spec prefetching code is doing something clever in interpreting 
>the keypath into a query based on the main objects and intermediate 
>objects in the keypath. I need batchFetchRelationship() to do a similar thing.

Let's say we have People -(to-many)-> Companies -(to-many)->Continents

You could first use batchFetchRelationship on your list of People to fetch 
all their Companies. Then use batchFetchRelationship on Companies, to fetch 
all their Continents. That should result in everything being fetched in 
just two trips to the db, which is the minimum you could do it. Am I 
missing something?

>Another problem with solution 2 is that the EODatabaseContext class which 
>is in the EOAccess layer is not available on the client side of a JC 
>application where I would also like to use this trick.

Aha. I don't do Java client stuff, so I was unfamiliar with that.


>However, it is still useful where one needs to preload a first level 
>to-many relationship. Here is an example method that implements your 
>suggestion for that:

That was very useful generic code, thanks.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.