Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function remove($key)
 {
     // TODO: If the keys are persistent as well (not yet implemented)
     //       and the collection is not initialized and orphanRemoval is
     //       not used we can issue a straight SQL delete/update on the
     //       association (table). Without initializing the collection.
     $this->_initialize();
     $removed = $this->_coll->remove($key);
     if ($removed) {
         $this->_changed();
         if ($this->_association !== null && $this->_association->isOneToMany() && $this->_association->orphanRemoval) {
             $this->_em->getUnitOfWork()->scheduleOrphanRemoval($removed);
         }
     }
     return $removed;
 }
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     if ($this->initialized && $this->isEmpty()) {
         return;
     }
     if ($this->association->isOneToMany() && $this->association->orphanRemoval) {
         foreach ($this->coll as $element) {
             $this->em->getUnitOfWork()->scheduleOrphanRemoval($element);
         }
     }
     $this->coll->clear();
     if ($this->association->isOwningSide) {
         $this->changed();
         $this->em->getUnitOfWork()->scheduleCollectionDeletion($this);
         $this->takeSnapshot();
     }
 }
Ejemplo n.º 3
0
 /**
  * Adds an element to the collection.
  * 
  * @param mixed $value
  * @param string $key 
  * @return boolean Always TRUE.
  * @override
  */
 public function add($value)
 {
     parent::add($value);
     if ($this->_hydrationFlag) {
         if ($this->_backRefFieldName) {
             // Set back reference to owner
             if ($this->_association->isOneToMany()) {
                 $this->_typeClass->getReflectionProperty($this->_backRefFieldName)->setValue($value, $this->_owner);
             } else {
                 // ManyToMany
                 $this->_typeClass->getReflectionProperty($this->_backRefFieldName)->getValue($value)->add($this->_owner);
             }
         }
     } else {
         $this->_changed();
     }
     return true;
 }