/**
  * Main Find Helper function that concludes a search, returning results
  *
  * @return array|RedBean_OODBBean
  */
 public function find($force_make = false, $force_array = false)
 {
     if (empty($this->related)) {
         $ft = 'find' . ucfirst($this->find);
         if ($this->params) {
             $r = $this->r->{$ft}($this->type, $this->makeQuery(), $this->params);
         } else {
             $r = $this->r->{$ft}($this->type);
         }
         if (!empty($this->preload)) {
             $this->r->preload($r, $this->preload);
         }
         if (!is_array($r) && !empty($r)) {
             $r = array($r);
         }
     } else {
         if ($this->find == 'all') {
             $this->find = '';
         }
         $rt = 'related' . ucfirst($this->find);
         if ($this->params) {
             $r = $this->r->{$rt}($this->related[0], $this->type, $this->makeQuery(), $this->params);
         } else {
             $r = $this->r->{$rt}($this->related[0], $this->type);
         }
         if (!is_array($r) && !empty($r)) {
             $r = array($r);
         }
         if (count($r) && count($this->related) > 1) {
             foreach ($r as $k => $b) {
                 if ($k === 0) {
                     continue;
                 }
                 foreach ($this->related as $bean) {
                     if (!$this->r->areRelated($b, $bean)) {
                         unset($r[$k]);
                     }
                 }
             }
         }
     }
     if ($force_make && empty($r)) {
         $r = array($this->r->_($this->type, $this->params_plain, true));
         if (!empty($this->related)) {
             $this->r->associate($r[0], $this->related);
         }
     }
     $this->free();
     if (count($r) > 1 || $force_array) {
         return $r;
     } elseif (is_array($r)) {
         return array_pop($r);
     } else {
         return null;
     }
 }
 private static function makeUpdate($bean, $path, $type, $operation)
 {
     $json = json_encode($bean->export());
     return self::$r->_('update', array('operation' => $operation, 'path' => $path, 'type' => $type, 'objectid' => $bean->id, 'object' => $json, 'created' => self::$r->isoDateTime(), 'hash' => sha1($json)), true);
 }