Hi,
Hector Virgen wrote:
>> But how do you deal with other properties? For example, your articles
>> have a "isPublished" flag. Now you want a list with n articles, which
>> are published (isPublished === 1), ordered by another property
>> "edited_on".
>
> I would pass in the criteria as array('published' => true). The mapper
> then maps that to "WHERE isPublished = 1". I don't support returning n
> articles in the mapper because my lazy-loading iterator handles that for
> me:
>
> $articles = $mapper->fetchAll(array('published' => true));
> assert($articles instanceof Default_Model_ArticleCollection); // true
> assert($articles instanceof SeekableIterator); // true
> $articles->seekTo(20);
> $article = $articles->current();
> assert($article instanceof Default_Model_Article); // true
Does it really perform well? Seems like your architecture requires n+1
queries if you want to echo a list of titles from the latest n articles (I
guess your mapper's fetchAll() method will just set the ids for every object
in the collection, matching your criteria. When your collection returns a
real object, the collection will ask the mapper for that particular object).
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?
--
Regards
Thomas