/** * @param array $ids * @param Collection $collection */ public function reverseTransform($ids, $collection) { if (count($ids) == 0) { // don't check for collection count, a straight clear doesnt initialize the collection $collection->clear(); return $collection; } $em = $this->getOption('em'); $metadata = $em->getClassMetadata($this->getOption('className')); $reflField = $metadata->getReflectionProperty($metadata->identifier[0]); foreach ($collection as $object) { $key = array_search($reflField->getValue($object), $ids); if (false === $key) { $collection->removeElement($object); } else { unset($ids[$key]); } } // @todo: This can be greatly optimized into a single SELECT .. WHERE id IN () query. foreach ($ids as $id) { $entity = $em->find($this->getOption('className'), $id); if (!$entity) { throw new TransformationFailedException("Selected entity of type '" . $this->getOption('className') . "' by id '" . $id . "' which is not present in the database."); } $collection->add($entity); } return $collection; }
/** * {@inheritdoc} */ public function clear() { if ($this->initialized && $this->isEmpty()) { return; } if ($this->mapping !== null && isset($this->mapping['embedded'])) { foreach ($this->coll as $element) { $this->dm->getUnitOfWork()->scheduleOrphanRemoval($element); } } $this->coll->clear(); $this->changed(); $this->dm->getUnitOfWork()->scheduleCollectionDeletion($this); $this->takeSnapshot(); }
/** * {@inheritdoc} */ public function clear() { if ($this->initialized && $this->isEmpty()) { return; } if ($this->mapping !== null && isset($this->mapping['embedded'])) { foreach ($this->coll as $element) { $this->uow->scheduleOrphanRemoval($element); } } $this->mongoData = array(); $this->coll->clear(); if ($this->mapping['isOwningSide']) { $this->changed(); $this->uow->scheduleCollectionDeletion($this); $this->takeSnapshot(); } }
public function testIsEmptyClear() { $this->assertEquals(false, $this->collection->isEmpty()); $this->collection->clear(); $this->assertEquals(true, $this->collection->isEmpty()); }
/** * Removes all of the elements from this collection. * @return void * @throws NotSupportedException */ public function clear() { parent::clear(); $this->loaded = false; }
/** * {@inheritdoc} */ public function clear() { $this->_initialize(); $result = $this->_coll->clear(); if ($this->_association->isOwningSide) { $this->_changed(); $this->_em->getUnitOfWork()->scheduleCollectionDeletion($this); } return $result; }