refreshRelated() public method

refresh refresh data of related objects from the database
public refreshRelated ( string $name = null ) : Doctrine_Record
$name string name of a related component. if set, this method only refreshes the specified related component
return Doctrine_Record this object
Example #1
0
 /**
  * Cascades an ongoing delete operation to related objects. Applies only on relations
  * that have 'delete' in their cascade options.
  * This is an application-level cascade. Related objects that participate in the
  * cascade and are not yet loaded are fetched from the database.
  * Exception: many-valued relations are always (re-)fetched from the database to
  * make sure we have all of them.
  *
  * @param Doctrine_Record  The record for which the delete operation will be cascaded.
  * @throws PDOException    If something went wrong at database level
  * @return void
  */
 protected function _cascadeDelete(Doctrine_Record $record, array &$deletions)
 {
     foreach ($record->getTable()->getRelations() as $relation) {
         if ($relation->isCascadeDelete()) {
             $fieldName = $relation->getAlias();
             // if it's a xToOne relation and the related object is already loaded
             // we don't need to refresh.
             if (!($relation->getType() == Doctrine_Relation::ONE && isset($record->{$fieldName}))) {
                 $record->refreshRelated($relation->getAlias());
             }
             $relatedObjects = $record->get($relation->getAlias());
             if ($relatedObjects instanceof Doctrine_Record && $relatedObjects->exists() && !isset($deletions[$relatedObjects->getOid()])) {
                 $this->_collectDeletions($relatedObjects, $deletions);
             } else {
                 if ($relatedObjects instanceof Doctrine_Collection && count($relatedObjects) > 0) {
                     // cascade the delete to the other objects
                     foreach ($relatedObjects as $object) {
                         if (!isset($deletions[$object->getOid()])) {
                             $this->_collectDeletions($object, $deletions);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @see Doctrine_Connection_UnitOfWork::_cascadeDelete()
  *      (most part copy&past from)
  *
  * @param Doctrine_Record  The record for which the delete operation will be cascaded.
  * @throws PDOException    If something went wrong at database level
  * @return null
  */
 protected function cascade(Doctrine_Record $record)
 {
     foreach ($record->getTable()->getRelations() as $relation) {
         /* @var $relation Doctrine_Relation_LocalKey */
         # build-in Doctrine cascade mechanism do all the work - skip
         if ($relation->isCascadeDelete()) {
             continue;
         }
         $cascade = $relation->offsetGet('cascade');
         # no instructions, no results - skip
         if (0 == count($cascade)) {
             continue;
         }
         $isCascadeDeleteTags = in_array('deleteTags', $cascade);
         $isCascadeInvalidateTags = in_array('invalidateTags', $cascade);
         # could be only 1 selected, otherwise skip
         if (!($isCascadeDeleteTags xor $isCascadeInvalidateTags)) {
             continue;
         }
         if ($isCascadeDeleteTags) {
             $definitions =& $this->tagNamesToDelete;
         } else {
             $definitions =& $this->tagNamesToInvalidate;
         }
         $fieldName = $relation->getAlias();
         if ($relation->getType() != Doctrine_Relation::ONE || isset($record->{$fieldName})) {
             $record->refreshRelated($relation->getAlias());
         }
         $relatedObjects = $record->get($relation->getAlias());
         if ($relatedObjects instanceof Doctrine_Record && $relatedObjects->exists() && !isset($definitions[$relatedObjects->getOid()])) {
             # invalidate collection version too
             $collectionName = sfCacheTaggingToolkit::obtainCollectionName($relatedObjects->getTable());
             if ($isCascadeDeleteTags) {
                 $this->tagNamesToInvalidate[$collectionName] = $collectionName;
             } elseif ($isCascadeInvalidateTags) {
                 $template = $relatedObjects->getTable()->getTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME);
                 if ($template->getOption('invalidateCollectionVersionOnUpdate')) {
                     $this->tagNamesToInvalidate[$collectionName] = $collectionName;
                 }
             }
             $this->collect($relatedObjects, $definitions);
             continue;
         }
         if (!$relatedObjects instanceof Doctrine_Collection || count($relatedObjects) == 0 || !$relatedObjects->getTable()->hasTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME)) {
             continue;
         }
         # invalidate collection version too
         $collectionName = sfCacheTaggingToolkit::obtainCollectionName($relatedObjects->getTable());
         if ($isCascadeDeleteTags) {
             $this->tagNamesToInvalidate[$collectionName] = $collectionName;
         } elseif ($isCascadeInvalidateTags) {
             $template = $relatedObjects->getTable()->getTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME);
             if ($template->getOption('invalidateCollectionVersionOnUpdate')) {
                 $this->tagNamesToInvalidate[$collectionName] = $collectionName;
             }
         }
         foreach ($relatedObjects as $object) {
             if (isset($definitions[$object->getOid()])) {
                 continue;
             }
             $this->collect($object, $definitions);
         }
     }
 }