adjusting the changes and adding some docs

This commit is contained in:
dogmatic69 2013-02-10 11:09:26 +00:00
parent 00abe27ef8
commit 83a11b7189

View file

@ -2678,39 +2678,42 @@ class Model extends Object implements CakeEventListener {
* @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
*/
public function find($type = 'first', $query = array()) {
$query = $this->_beforeFind($type, $query);
$this->findQueryType = $type;
$this->id = $this->getID();
$query = $this->buildQuery($type, $query);
if (is_null($query)) {
return null;
}
return $this->_afterFind($type, $query);
return $this->_readDataSource($type, $query);
}
/**
* Before running a find
* Read from the datasource
*
* Model::_readDataSource() is used by all find() calls to read from the data source and can be overloaded to allow
* caching of datasource calls.
*
* @param string $type the find type to run
* @param array $query the finds query params
* {{{
* protected function _readDataSource($type, $query) {
* $cacheName = md5(json_encode($query));
* $cache = Cache::read($cacheName, 'cache-config-name');
* if ($cache !== false) {
* return $cache;
* }
*
* $results = parent::_readDataSource($type, $query);
* Cache::write($cacheName, $results, 'cache-config-name');
* return $results;
* }
* }}}
*
* @return array|null
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
* @return array
*/
protected function _beforeFind($type, $query) {
$this->findQueryType = $type;
$this->id = $this->getID();
return $this->buildQuery($type, $query);
}
/**
* After running a find
*
* @param string $type the find type to run
* @param array $query the finds query params
* @param array $results they results from the find
*
* @return array|null
*/
protected function _afterFind($type, $query) {
protected function _readDataSource($type, $query) {
$results = $this->getDataSource()->read($this, $query);
$this->resetAssociations();
@ -2727,7 +2730,6 @@ class Model extends Object implements CakeEventListener {
if ($this->findMethods[$type] === true) {
return $this->{'_find' . ucfirst($type)}('after', $query, $results);
}
}
/**