RedBeanPHP\AssociationManager::clearRelations PHP Method

clearRelations() public method

Removes all relations for a bean. This method breaks every connection between a certain bean $bean and every other bean of type $type. Warning: this method is really fast because it uses a direct SQL query however it does not inform the models about this. If you want to notify FUSE models about deletion use a foreach-loop with unassociate() instead. (that might be slower though)
public clearRelations ( redbeanphp\OODBBean $bean, string $type ) : void
$bean redbeanphp\OODBBean reference bean
$type string type of beans that need to be unassociated
return void
    public function clearRelations(OODBBean $bean, $type)
    {
        $this->oodb->store($bean);
        try {
            $this->writer->deleteRelations($bean->getMeta('type'), $type, $bean->id);
        } catch (SQLException $exception) {
            $this->handleException($exception);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Tags a bean or returns tags associated with a bean.
  * If $tagList is NULL or omitted this method will return a
  * comma separated list of tags associated with the bean provided.
  * If $tagList is a comma separated list (string) of tags all tags will
  * be associated with the bean.
  * You may also pass an array instead of a string.
  * 
  * Tag list can be either an array with tag names or a comma separated list
  * of tag names.
  *
  * @param OODBBean $bean    bean to be tagged
  * @param array|string     $tagList a list of tags
  *
  * @return array
  */
 public function tag(OODBBean $bean, $tagList = NULL)
 {
     if (is_null($tagList)) {
         $tags = $bean->sharedTag;
         $foundTags = array();
         foreach ($tags as $tag) {
             $foundTags[] = $tag->title;
         }
         return $foundTags;
     }
     $this->associationManager->clearRelations($bean, 'tag');
     $this->addTags($bean, $tagList);
     return $tagList;
 }
All Usage Examples Of RedBeanPHP\AssociationManager::clearRelations