> > Lazy-loading sounds good, but wouldn't it be better, if your fetchAll() > method would fetch every row matching your criteria and cache the data? No > need to instantiate each object in your result set, when you are just > preparing the set, this can still happen in your collection... or are you > still doing this? >
I am not going with this approach because it doesn't perform as well you'd think, especially if you want your collection to be compatible with Zend_Paginator. For example, let's say fetchAll() finds 100,000 records that match your criteria (not unlikely in my data set). That's obviously way too much data to supply the iterator with. But if you set a limit, say, 20, then the iterator only knows about 20 records, and Zend_Paginator won't paginate it correctly (it'll also think there are only 20 records). It may be possible to "trick" Zend_Paginator by passing it a collection with only 20 records, but have the collection simply do nothing when calling skipTo($position). Also, it would need to lie when you call count(). This seems awkward. Another alternative would be to have the collection lazy-load from the mapper when current() is first called, because at this point it will know how many to skip. But it will not know what the paginator's limit is... is it 20 per page, or 50, or 100? -- Hector
