Exemplo n.º 1
0
 /**
  * Returns all the beans associated with $bean.
  * This method will return an array containing all the beans that have
  * been associated once with the associate() function and are still
  * associated with the bean specified. The type parameter indicates the
  * type of beans you are looking for. You can also pass some extra SQL and
  * values for that SQL to filter your results after fetching the
  * related beans.
  *
  * Don't try to make use of subqueries, a subquery using IN() seems to
  * be slower than two queries!
  *
  * Since 3.2, you can now also pass an array of beans instead just one
  * bean as the first parameter.
  *
  * @param OODBBean|array $bean the bean you have
  * @param string         $type      the type of beans you want
  * @param string         $sql       SQL snippet for extra filtering
  * @param array          $bindings  values to be inserted in SQL slots
  *
  * @return array
  */
 public function related($bean, $type, $sql = '', $bindings = array())
 {
     $sql = $this->writer->glueSQLCondition($sql);
     $rows = $this->relatedRows($bean, $type, $sql, $bindings);
     $links = array();
     foreach ($rows as $key => $row) {
         if (!isset($links[$row['id']])) {
             $links[$row['id']] = array();
         }
         $links[$row['id']][] = $row['linked_by'];
         unset($rows[$key]['linked_by']);
     }
     $beans = $this->oodb->convertToBeans($type, $rows);
     foreach ($beans as $bean) {
         $bean->setMeta('sys.belongs-to', $links[$bean->id]);
     }
     return $beans;
 }
Exemplo n.º 2
0
 /**
  * Nukes the entire database.
  * This will remove all schema structures from the database.
  * Only works in fluid mode. Be careful with this method.
  *
  * @warning dangerous method, will remove all tables, columns etc.
  *
  * @return void
  */
 public static function nuke()
 {
     if (!self::$redbean->isFrozen()) {
         self::$writer->wipeAll();
     }
 }