habtm as $key=>$value){ $fk_this = $value[0]; $fk_otherModel = $value[1]; $otherModelName = $value[2]; loadModel($otherModelName); $otherModel = new $otherModelName(); $otherTableName = $otherModel->useTable; $join_statement .= " JOIN ".$key." on ".$this->name.".id=".$key.".".$fk_this; $join_statement .= " JOIN ".$otherTableName." as ".$otherModelName." on ".$key.".".$fk_otherModel."=".$otherModelName.".id"; } return $join_statement; } function findAll($conditions = null, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) { $db =& ConnectionManager::getDataSource($this->useDbConfig); $this->id = $this->getID(); $offset = null; if ($page > 1 && $limit != null) { $offset = ($page - 1) * $limit; } if ($order == null) { $order = array(); } else { $order = array($order); } $queryData = array('conditions' => $conditions, 'fields' => '*', 'joins' => array($this->prepareJoinStatement()), 'limit' => $limit, 'offset' => $offset, 'order' => $order ); $ret = $this->beforeFind($queryData); if (is_array($ret)) { $queryData = $ret; } elseif ($ret === false) { return null; } $return = $this->afterFind($db->read($this, $queryData, $recursive)); if (isset($this->__backAssociation)) { $this->__resetAssociations(); } return $return; } } ?>