Re: Standalone prefetch without main query?

John Pollard <[email protected]>
Newsgroups gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
Jonathan

At 10:39 05/11/2002 -0600, Jonathan Rochkind wrote:
>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?

One of the problems with the batchFetchRelationship approach is that it is 
built up with one OR per object in the NSArray passed to it. Am I right in 
thinking that most databases will limit the number of ORs in an SQL 
statement? In my case I happen to know the top level NSArray will not be 
too large, but the second level (Companies in your example above) could 
contain thousands of results. When prefetching as part of a fetch spec some 
clever code bases the query for Continents (in your example) on the 
criteria of the main query for People, not requiring an OR for each Company 
returned. I wish batchFetchRelationship() could be that clever.

John
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.