Persephone Search Iterator
Document

Search Iterator

by Group Public on Friday October 17 2008 @ 15:14:10 (1/1 Points)

API ↪Reference ✑ Reply ✓ Stick It ✗ Ditch It ⚐ Tag It

Searching entities is done via iterators, rather than loading the entire result immediately.

Search

By calling the search function of an entity an iterator will be returned. This iterator should mimic the native language iterator type, for example in PHP this means it can be used in a foreach loop.

foreach( MyEntity::search( DBS_Query::matchAll() ) as $item ) {
  print( "{$item->name}\n" );
}

iterator::loadAll

In cases where the entire result set needs to be fully loaded there is a loadAll function. The return of loadAll is an array or map, but there are a few manners in which it can be called.

Simple Array, loadAll()

Returns an array containing all of the entities as loaded by the search.

Map, loadAll( fieldKey )

Returns a map containing all the entities as loaded by the search, where the value of "fieldKey" in the entity is used as the key in the map.

You must be certain the type of this field can be used as a key, otherwise you will have unexpected results.

Map, loadAll( fieldKey, fieldValue )

Loads map where the value of "fieldKey" is the map key, and the value of "fieldValue" is the value in the map.

This is useful for cases where you simply wish to retrieve a name/value pair from the matched entities. You may wish to consider using a field limiter if you intend on using this loadAll.

© 2008-2010 edA-qa mort-ora-y
Using Persephone and TestPlan
Tag: