ERXRecursiveBatchFetching

4 views
Skip to first unread message

Mike Schrag

unread,
Mar 3, 2007, 8:23:45 AM3/3/07
to wot...@googlegroups.com
For such a useful class, ERXRecursiveBatchFetching has an
intimidating name. Say you have an array of Person EO's and you're
about to call .employingCompany() on all of them, or you have an
array of Company EO's and you want to call employedPeople() on all of
them. You're about to fire off a bunch of individual queries for
each EO, and EOF doesn't have the context to be particularly smart
about that. Enter ERXRecursiveBatchFetching. There are a slew of
methods that let you prefetch keypaths on arrays of EO's with
optimized queries.

So in the above examples, you can say
ERXRecursiveBatchFetching.batchFetch(people, "employingCompany");
ERXRecursiveBatchFetching.batchFetch(companies, "employedPeople");

and when you traverse the relationships, they'll be already faulted
for you in a smart way.

But note that you can also pass in a keypath, not just a key, and it
will attempt to put together an optimized fetch. So you could even
pass in, for instance, "employingCompany.customers".

There's also a batchFetchAndRetrieve method for the case where you're
passing in a single keypath where it will go ahead and return the
results for you also.

So watch your queries ... If you're firing a bunch of relationship
traversals, this class can be an easy and HUGE performance gain, just
with a scary name.

ms


Reply all
Reply to author
Forward
0 new messages