RedBeanPHP\AssociationManager::unassociate PHP Méthode

unassociate() public méthode

Breaks the association between two beans. This method unassociates two beans. If the method succeeds the beans will no longer form an association. In the database this means that the association record will be removed. This method uses the OODB trash() method to remove the association links, thus giving FUSE models the opportunity to hook-in additional business logic. If the $fast parameter is set to boolean TRUE this method will remove the beans without their consent, bypassing FUSE. This can be used to improve performance.
public unassociate ( $beans1, $beans2, boolean $fast = NULL ) : void
$fast boolean if TRUE, removes the entries by query without FUSE
Résultat void
    public function unassociate($beans1, $beans2, $fast = NULL)
    {
        $beans1 = !is_array($beans1) ? array($beans1) : $beans1;
        $beans2 = !is_array($beans2) ? array($beans2) : $beans2;
        foreach ($beans1 as $bean1) {
            foreach ($beans2 as $bean2) {
                try {
                    $this->oodb->store($bean1);
                    $this->oodb->store($bean2);
                    $type1 = $bean1->getMeta('type');
                    $type2 = $bean2->getMeta('type');
                    $row = $this->writer->queryRecordLink($type1, $type2, $bean1->id, $bean2->id);
                    $linkType = $this->getTable(array($type1, $type2));
                    if ($fast) {
                        $this->writer->deleteRecord($linkType, array('id' => $row['id']));
                        return;
                    }
                    $beans = $this->oodb->convertToBeans($linkType, array($row));
                    if (count($beans) > 0) {
                        $bean = reset($beans);
                        $this->oodb->trash($bean);
                    }
                } catch (SQLException $exception) {
                    $this->handleException($exception);
                }
            }
        }
    }

Usage Example

Exemple #1
0
 /**
  * Removes all sepcified tags from the bean. The tags specified in
  * the second parameter will no longer be associated with the bean.
  * 
  * Tag list can be either an array with tag names or a comma separated list
  * of tag names.
  *
  * @param  OODBBean $bean    tagged bean
  * @param  array|string     $tagList list of tags (names)
  *
  * @return void
  */
 public function untag($bean, $tagList)
 {
     $tags = $this->extractTagsIfNeeded($tagList);
     foreach ($tags as $tag) {
         if ($t = $this->findTagByTitle($tag)) {
             $this->associationManager->unassociate($bean, $t);
         }
     }
 }
All Usage Examples Of RedBeanPHP\AssociationManager::unassociate