/** * 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 = R::$ft($this->type, $this->makeQuery(), $this->params); } else { $r = R::$ft($this->type); } if (!empty($this->preload)) { 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 = R::$rt($this->related[0], $this->type, $this->makeQuery(), $this->params); } else { $r = 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 (!R::areRelated($b, $bean)) { unset($r[$k]); } } } } } if ($force_make && empty($r)) { $r = array(R::_($this->type, $this->params_plain, true)); if (!empty($this->related)) { 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; } }