/** * Initializes the collection by loading its contents from the database * if the collection is not yet initialized. */ public function initialize() { if ($this->initialized || !$this->mapping) { return; } $newObjects = array(); if ($this->isDirty) { // Remember any NEW objects added through add() $newObjects = $this->coll->toArray(); } $this->initialized = true; $this->coll->clear(); $this->uow->loadCollection($this); $this->takeSnapshot(); $this->mongoData = array(); // Reattach any NEW objects added through add() if ($newObjects) { foreach ($newObjects as $key => $obj) { if (CollectionHelper::isHash($this->mapping['strategy'])) { $this->coll->set($key, $obj); } else { $this->coll->add($obj); } } $this->isDirty = true; } }