/** * Performs the recursive finding with the criteria. * @param \Database\schema\Criteria $criteria the query criteria */ public function find($criteria = null) { if ($this->_parent === null) { $query = new Query($this, $criteria); $this->_finder->baseLimited = $criteria->offset >= 0 || $criteria->limit >= 0; $this->buildQuery($query); $this->_finder->baseLimited = false; $this->runQuery($query); } elseif (!$this->_joined && !empty($this->_parent->records)) { $query = new Query($this->_parent); $this->_joined = true; $query->join($this); $this->buildQuery($query); $this->_parent->runQuery($query); } /** @var $child Element */ foreach ($this->children as $child) { // find recursively $child->find(); } foreach ($this->stats as $stat) { $stat->query(); } }