Table of Contents
8. Special Topics
7. Gii Support
« Previous
8.1. Multimodel Collections
Next »

8. Special Topics

Table of Contents

AuthorDariusz Górecki

This section covers some special topics, that need to bye mentioned

Behaviors

Performance

Use Cursor Flag

Now we can set that all records returned by findAll* methods will return EMongoCursor instead of raw array, EMongoCursor implements Iterator interface and can be used with ie. foreach loop.

EMongoCursor will instantiate objects in lazy-loading way, only on first use.

By default useCursor flag is set to FALSE to keep backwards compatibility, note: - Cursor does not implement ArrayAccess interface, because offset access to cursor is very ineffective, and pointless - You can set useCursor flag in different scopes - globally in EMongoDB class, by setting $useCursor variable - Per model: ModelClass::model()->setUseCursor(true); - And per model instance: $modelInstance->setUseCursor(true);

Massive hand operations

// Example mass insert (you will want to disable fsyncField for this:
for($i=0; $i<1000; $i++)
{
    $c = new Client;
    $c->personal_number = $i;
    $c->validate(); // You can omit this if you want
    $c->getCollection()->insert($c->toArray());
}
8. Special Topics
Table of Contents
« Previous
7. Gii Support
Next »
8.1. Multimodel Collections