Merge branch '2.0-models' into 2.0

This commit is contained in:
Juan Basso 2011-02-26 19:10:07 -03:00
commit 2414ad8c8f
8 changed files with 431 additions and 529 deletions

View file

@ -32,112 +32,6 @@ class DataSource extends Object {
*/
public $connected = false;
/**
* Print full query debug info?
*
* @var boolean
* @access public
*/
public $fullDebug = false;
/**
* Error description of last query
*
* @var unknown_type
* @access public
*/
public $error = null;
/**
* String to hold how many rows were affected by the last SQL operation.
*
* @var string
* @access public
*/
public $affected = null;
/**
* Number of rows in current resultset
*
* @var int
* @access public
*/
public $numRows = null;
/**
* Time the last query took
*
* @var int
* @access public
*/
public $took = null;
/**
* The starting character that this DataSource uses for quoted identifiers.
*
* @var string
* @access public
*/
public $startQuote = null;
/**
* The ending character that this DataSource uses for quoted identifiers.
*
* @var string
* @access public
*/
public $endQuote = null;
/**
* Result
*
* @var array
* @access protected
*/
protected $_result = null;
/**
* Queries count.
*
* @var int
* @access protected
*/
protected $_queriesCnt = 0;
/**
* Total duration of all queries.
*
* @var unknown_type
* @access protected
*/
protected $_queriesTime = null;
/**
* Log of queries executed by this DataSource
*
* @var unknown_type
* @access protected
*/
protected $_queriesLog = array();
/**
* Maximum number of items in query log
*
* This is to prevent query log taking over too much memory.
*
* @var int Maximum number of queries in the queries log.
* @access protected
*/
protected $_queriesLogMax = 200;
/**
* Caches serialzed results of executed queries
*
* @var array Maximum number of queries in the queries log.
* @access protected
*/
protected $_queryCache = array();
/**
* The default configuration of a specific DataSource
*
@ -162,14 +56,6 @@ class DataSource extends Object {
*/
protected $_sources = null;
/**
* A reference to the physical connection of this DataSource
*
* @var array
* @access public
*/
public $connection = null;
/**
* The DataSource configuration
*
@ -178,14 +64,6 @@ class DataSource extends Object {
*/
public $config = array();
/**
* The DataSource configuration key name
*
* @var string
* @access public
*/
public $configKeyName = null;
/**
* Whether or not this DataSource is in the middle of a transaction
*
@ -238,21 +116,7 @@ class DataSource extends Object {
Cache::write($key, $data, '_cake_model_');
}
$this->_sources = $sources;
return $sources;
}
/**
* Convenience method for DboSource::listSources(). Returns source names in lowercase.
*
* @param boolean $reset Whether or not the source list should be reset.
* @return array Array of sources available in this datasource
*/
public function sources($reset = false) {
if ($reset === true) {
$this->_sources = null;
}
return array_map('strtolower', $this->listSources());
return $this->_sources = $sources;
}
/**
@ -261,7 +125,7 @@ class DataSource extends Object {
* @param Model $model
* @return array Array of Metadata for the $model
*/
public function describe($model) {
public function describe(Model $model) {
if ($this->cacheSources === false) {
return null;
}
@ -326,7 +190,7 @@ class DataSource extends Object {
* @param array $values An Array of values to save.
* @return boolean success
*/
public function create($model, $fields = null, $values = null) {
public function create(Model $model, $fields = null, $values = null) {
return false;
}
@ -339,7 +203,7 @@ class DataSource extends Object {
* @param array $queryData An array of query data used to find the data you want
* @return mixed
*/
public function read($model, $queryData = array()) {
public function read(Model $model, $queryData = array()) {
return false;
}
@ -353,7 +217,7 @@ class DataSource extends Object {
* @param array $values Array of values to be update $fields to.
* @return boolean Success
*/
public function update($model, $fields = null, $values = null) {
public function update(Model $model, $fields = null, $values = null) {
return false;
}
@ -365,7 +229,7 @@ class DataSource extends Object {
* @param Model $model The model class having record(s) deleted
* @param mixed $id Primary key of the model
*/
public function delete($model, $id = null) {
public function delete(Model $model, $id = null) {
if ($id == null) {
$id = $model->id;
}
@ -412,20 +276,6 @@ class DataSource extends Object {
return true;
}
/**
* Returns true if the DataSource supports the given interface (method)
*
* @param string $interface The name of the interface (method)
* @return boolean True on success
*/
public function isInterfaceSupported($interface) {
static $methods = false;
if ($methods === false) {
$methods = array_map('strtolower', get_class_methods($this));
}
return in_array(strtolower($interface), $methods);
}
/**
* Sets the configuration for the DataSource.
* Merges the $config information with the _baseConfig and the existing $config property.
@ -479,7 +329,7 @@ class DataSource extends Object {
* @access public
* @todo Remove and refactor $assocData, ensure uses of the method have the param removed too.
*/
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $stack) {
function insertQueryData($query, $data, $association, $assocData, Model $model, Model $linkModel, $stack) {
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
foreach ($keys as $key) {
@ -559,7 +409,7 @@ class DataSource extends Object {
* @param string $key Key name to make
* @return string Key name for model.
*/
public function resolveKey($model, $key) {
public function resolveKey(Model $model, $key) {
return $model->alias . $key;
}
@ -570,8 +420,7 @@ class DataSource extends Object {
*/
public function __destruct() {
if ($this->_transactionStarted) {
$null = null;
$this->rollback($null);
$this->rollback();
}
if ($this->connected) {
$this->close();

View file

@ -209,21 +209,19 @@ class DboMysql extends DboSource {
$this->map = array();
$numFields = $results->columnCount();
$index = 0;
$j = 0;
while ($j < $numFields) {
$column = $results->getColumnMeta($j);
if (!empty($column['native_type'])) {
$type = $column['native_type'];
} else {
while ($numFields-- > 0) {
$column = $results->getColumnMeta($index);
if (empty($column['native_type'])) {
$type = ($column['len'] == 1) ? 'boolean' : 'string';
} else {
$type = $column['native_type'];
}
if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) {
$this->map[$index++] = array($column['table'], $column['name'], $type);
} else {
$this->map[$index++] = array(0, $column['name'], $type);
}
$j++;
}
}
@ -238,15 +236,14 @@ class DboMysql extends DboSource {
foreach ($this->map as $col => $meta) {
list($table, $column, $type) = $meta;
$resultRow[$table][$column] = $row[$col];
if ($type == 'boolean' && !is_null($row[$col])) {
if ($type === 'boolean' && !is_null($row[$col])) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
}
}
return $resultRow;
} else {
$this->_result->closeCursor();
return false;
}
$this->_result->closeCursor();
return false;
}
/**
@ -305,7 +302,7 @@ class DboMysql extends DboSource {
foreach ($cols as $column) {
$fields[$column->Field] = array(
'type' => $this->column($column->Type),
'null' => ($column->Null == 'YES' ? true : false),
'null' => ($column->Null === 'YES' ? true : false),
'default' => $column->Default,
'length' => $this->length($column->Type),
);
@ -410,7 +407,7 @@ class DboMysql extends DboSource {
* @param string $enc Database encoding
*/
function setEncoding($enc) {
return $this->_execute('SET NAMES ' . $enc) != false;
return $this->_execute('SET NAMES ' . $enc) !== false;
}
/**
@ -500,7 +497,7 @@ class DboMysql extends DboSource {
}
$colList = array_merge($colList, $this->_alterIndexes($curTable, $indexes));
$colList = array_merge($colList, $this->_alterTableParameters($curTable, $tableParameters));
$out .= "\t" . join(",\n\t", $colList) . ";\n\n";
$out .= "\t" . implode(",\n\t", $colList) . ";\n\n";
}
}
return $out;
@ -517,7 +514,7 @@ class DboMysql extends DboSource {
function dropSchema(CakeSchema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table == $curTable) {
if (!$table || $table === $curTable) {
$out .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n";
}
}
@ -584,7 +581,7 @@ class DboMysql extends DboSource {
/**
* Returns an detailed array of sources (tables) in the database.
*
* @param string $name Table name to get parameters
* @param string $name Table name to get parameters
* @return array Array of tablenames in the database
*/
function listDetailedSources($name = null) {
@ -629,7 +626,7 @@ class DboMysql extends DboSource {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '('.$real['limit'].')';
$col .= '(' . $real['limit'] . ')';
}
return $col;
}
@ -643,19 +640,19 @@ class DboMysql extends DboSource {
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
if (($col === 'tinyint' && $limit == 1) || $col === 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
if (strpos($col, 'char') !== false || $col === 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false || $col == 'binary') {
if (strpos($col, 'blob') !== false || $col === 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {

File diff suppressed because it is too large Load diff

View file

@ -798,7 +798,7 @@ class Model extends Object {
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
if ($db->isInterfaceSupported('listSources')) {
if (method_exists($db, 'listSources')) {
$sources = $db->listSources();
if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
throw new MissingTableException(array(
@ -981,7 +981,7 @@ class Model extends Object {
if (!is_array($this->_schema) || $field === true) {
$db = $this->getDataSource();
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
if ($db->isInterfaceSupported('describe') && $this->useTable !== false) {
if (method_exists($db, 'describe') && $this->useTable !== false) {
$this->_schema = $db->describe($this, $field);
} elseif ($this->useTable === false) {
$this->_schema = array();
@ -2073,7 +2073,7 @@ class Model extends Object {
/**
* Queries the datasource and returns a result set array.
*
* Also used to perform new-notation finds, where the first argument is type of find operation to perform
* Also used to perform notation finds, where the first argument is type of find operation to perform
* (all / first / count / neighbors / list / threaded ),
* second parameter options for finding ( indexed array, including: 'conditions', 'limit',
* 'recursive', 'page', 'fields', 'offset', 'order')
@ -2109,43 +2109,31 @@ class Model extends Object {
*
* Behaviors and find types can also define custom finder keys which are passed into find().
*
* Specifying 'fields' for new-notation 'list':
* Specifying 'fields' for notation 'list':
*
* - If no fields are specified, then 'id' is used for key and 'model->displayField' is used for value.
* - If a single field is specified, 'id' is used for key and specified field is used for value.
* - If three fields are specified, they are used (in order) for key, value and group.
* - Otherwise, first and second fields are used for key and value.
*
* @param array $conditions SQL conditions array, or type of find operation (all / first / count /
* neighbors / list / threaded)
* @param mixed $fields Either a single string of a field name, or an array of field names, or
* options for matching
* @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
* @param integer $recursive The number of levels deep to fetch associated records
* @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 Array of records
* @access public
* @link http://book.cakephp.org/view/1018/find
*/
function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
if (!is_string($conditions) || (is_string($conditions) && !array_key_exists($conditions, $this->_findMethods))) {
$type = 'first';
$query = array_merge(compact('conditions', 'fields', 'order', 'recursive'), array('limit' => 1));
} else {
list($type, $query) = array($conditions, $fields);
}
public function find($type = 'first', $query = array()) {
$this->findQueryType = $type;
$this->id = $this->getID();
$query = array_merge(
array(
'conditions' => null, 'fields' => null, 'joins' => array(), 'limit' => null,
'offset' => null, 'order' => null, 'page' => null, 'group' => null, 'callbacks' => true
'offset' => null, 'order' => null, 'page' => 1, 'group' => null, 'callbacks' => true
),
(array)$query
);
if ($type != 'all') {
if ($type !== 'all') {
if ($this->_findMethods[$type] === true) {
$query = $this->{'_find' . ucfirst($type)}('before', $query);
}
@ -2183,15 +2171,11 @@ class Model extends Object {
}
}
if (!$db = $this->getDataSource()) {
return false;
}
$results = $db->read($this, $query);
$results = $this->getDataSource()->read($this, $query);
$this->resetAssociations();
if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
$results = $this->__filterResults($results);
$results = $this->_filterResults($results);
}
$this->findQueryType = null;
@ -2212,14 +2196,13 @@ class Model extends Object {
* @param array $query
* @param array $data
* @return array
* @access protected
* @see Model::find()
*/
function _findFirst($state, $query, $results = array()) {
if ($state == 'before') {
protected function _findFirst($state, $query, $results = array()) {
if ($state === 'before') {
$query['limit'] = 1;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
if (empty($results[0])) {
return false;
}
@ -2234,11 +2217,10 @@ class Model extends Object {
* @param array $query
* @param array $data
* @return int The number of records found, or false
* @access protected
* @see Model::find()
*/
function _findCount($state, $query, $results = array()) {
if ($state == 'before') {
protected function _findCount($state, $query, $results = array()) {
if ($state === 'before') {
$db = $this->getDataSource();
if (empty($query['fields'])) {
$query['fields'] = $db->calculate($this, 'count');
@ -2249,7 +2231,7 @@ class Model extends Object {
}
$query['order'] = false;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
if (isset($results[0][0]['count'])) {
return intval($results[0][0]['count']);
} elseif (isset($results[0][$this->alias]['count'])) {
@ -2266,11 +2248,10 @@ class Model extends Object {
* @param array $query
* @param array $data
* @return array Key/value pairs of primary keys/display field values of all records found
* @access protected
* @see Model::find()
*/
function _findList($state, $query, $results = array()) {
if ($state == 'before') {
protected function _findList($state, $query, $results = array()) {
if ($state === 'before') {
if (empty($query['fields'])) {
$query['fields'] = array("{$this->alias}.{$this->primaryKey}", "{$this->alias}.{$this->displayField}");
$list = array("{n}.{$this->alias}.{$this->primaryKey}", "{n}.{$this->alias}.{$this->displayField}", null);
@ -2279,14 +2260,14 @@ class Model extends Object {
$query['fields'] = String::tokenize($query['fields']);
}
if (count($query['fields']) == 1) {
if (count($query['fields']) === 1) {
if (strpos($query['fields'][0], '.') === false) {
$query['fields'][0] = $this->alias . '.' . $query['fields'][0];
}
$list = array("{n}.{$this->alias}.{$this->primaryKey}", '{n}.' . $query['fields'][0], null);
$query['fields'] = array("{$this->alias}.{$this->primaryKey}", $query['fields'][0]);
} elseif (count($query['fields']) == 3) {
} elseif (count($query['fields']) === 3) {
for ($i = 0; $i < 3; $i++) {
if (strpos($query['fields'][$i], '.') === false) {
$query['fields'][$i] = $this->alias . '.' . $query['fields'][$i];
@ -2309,7 +2290,7 @@ class Model extends Object {
}
list($query['list']['keyPath'], $query['list']['valuePath'], $query['list']['groupPath']) = $list;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
if (empty($results)) {
return array();
}
@ -2328,7 +2309,7 @@ class Model extends Object {
* @return array
*/
protected function _findNeighbors($state, $query, $results = array()) {
if ($state == 'before') {
if ($state === 'before') {
extract($query);
$conditions = (array)$conditions;
if (isset($field) && isset($value)) {
@ -2345,7 +2326,7 @@ class Model extends Object {
$query['field'] = $field;
$query['value'] = $value;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
extract($query);
unset($query['conditions'][$field . ' <']);
$return = array();
@ -2364,9 +2345,9 @@ class Model extends Object {
if (!array_key_exists('prev', $return)) {
$return['prev'] = $return2[0];
}
if (count($return2) == 2) {
if (count($return2) === 2) {
$return['next'] = $return2[1];
} elseif (count($return2) == 1 && !$return['prev']) {
} elseif (count($return2) === 1 && !$return['prev']) {
$return['next'] = $return2[0];
} else {
$return['next'] = null;
@ -2385,9 +2366,9 @@ class Model extends Object {
* @return array Threaded results
*/
protected function _findThreaded($state, $query, $results = array()) {
if ($state == 'before') {
if ($state === 'before') {
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
$return = $idMap = array();
$ids = Set::extract($results, '{n}.' . $this->alias . '.' . $this->primaryKey);
@ -2427,9 +2408,8 @@ class Model extends Object {
* @param array Results to filter
* @param boolean $primary If this is the primary model results (results from model where the find operation was performed)
* @return array Set of filtered results
* @access private
*/
function __filterResults($results, $primary = true) {
protected function _filterResults($results, $primary = true) {
$return = $this->Behaviors->trigger(
'afterFind',
array(&$this, $results, $primary),

View file

@ -26,7 +26,7 @@ if ($noLogs):
$logs = array();
foreach ($sources as $source):
$db =& ConnectionManager::getDataSource($source);
if (!$db->isInterfaceSupported('getLog')):
if (!method_exists($db, 'getLog')):
continue;
endif;
$logs[$source] = $db->getLog();

View file

@ -288,7 +288,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
$result = $this->Tree->find(null, array('name', $parentField), $modelClass . '.' . $leftField . ' desc');
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
$expected = array($modelClass => array('name' => 'testAddOrphan', $parentField => null));
$this->assertEqual($result, $expected);
@ -307,7 +307,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data= $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$initialCount = $this->Tree->find('count');
$this->Tree->create();
@ -367,7 +367,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null));
$result = $this->Tree->find(null, array('name', $parentField), $modelClass . '.' . $leftField . ' desc');
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
$expected = array($modelClass => array('name' => 'testAddNotIndexed', $parentField => null));
$this->assertEqual($result, $expected);
@ -387,10 +387,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id= $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
$direct = $this->Tree->children($parent_id, true, array('id', 'name', $parentField, $leftField, $rightField));
@ -414,10 +414,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->whitelist = array($parentField, 'name', 'description');
$this->Tree->saveField($parentField, $parent_id);
@ -461,10 +461,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1.1'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.1')));
$parent_id = $parent[$modelClass]['id'];
$data= $this->Tree->find(array($modelClass . '.name' => '1.2'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
@ -490,10 +490,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1.2'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2')));
$parent_id = $parent[$modelClass]['id'];
$data= $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data= $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
@ -519,10 +519,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$expects = $this->Tree->find('all');
$before = $this->Tree->read(null, $data[$modelClass]['id']);
@ -606,7 +606,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2')));
$this->Tree->moveUp($data[$modelClass]['id']);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -628,7 +628,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->moveUp($data[$modelClass]['id']);
@ -651,7 +651,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveUp($data[$modelClass]['id'], 2);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -682,7 +682,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveUp($data[$modelClass]['id'], true);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -713,7 +713,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->moveDown($data[$modelClass]['id']);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -735,7 +735,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2')));
$this->Tree->moveDown($data[$modelClass]['id']);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -757,7 +757,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveDown($data[$modelClass]['id'], true);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -788,7 +788,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveDown($data[$modelClass]['id'], 2);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -819,7 +819,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->saveField('name', 'renamed');
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -849,7 +849,7 @@ class NumberTreeTest extends CakeTestCase {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 1);
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->save(array($parentField => null));
@ -1077,7 +1077,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id= $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
@ -1108,7 +1108,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->childCount(null, true);
@ -1129,7 +1129,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
$this->Tree->id= $data[$modelClass]['id'];
$result = $this->Tree->getParentNode(null, array('name'));
@ -1148,7 +1148,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
$this->Tree->id= $data[$modelClass]['id'];
$result = $this->Tree->getPath(null, array('name'));
@ -1171,7 +1171,7 @@ class NumberTreeTest extends CakeTestCase {
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id= $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
@ -1203,13 +1203,13 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(3, 3);
$nodes = $this->Tree->find('list', array('order' => $leftField));
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->moveDown($data[$modelClass]['id']);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2.1')));
$this->Tree->moveDown($data[$modelClass]['id']);
$data = $this->Tree->find(array($modelClass . '.name' => '1.3.2.2'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.3.2.2')));
$this->Tree->moveDown($data[$modelClass]['id']);
$unsortedNodes = $this->Tree->find('list', array('order' => $leftField));
@ -1676,10 +1676,10 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id= $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
$direct = $this->Tree->children($parent_id, true, array('name', $leftField, $rightField));
@ -1702,10 +1702,10 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->whitelist = array($parentField, 'name', 'description');
$this->Tree->saveField($parentField, $parent_id);
@ -1794,7 +1794,7 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));
@ -1825,7 +1825,7 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));

View file

@ -5087,7 +5087,7 @@ class ModelReadTest extends BaseModelTest {
$this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image');
$Portfolio = new Portfolio();
$result = $Portfolio->find(array('id' => 2), null, null, 3);
$result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3));
$expected = array(
'Portfolio' => array(
'id' => 2,
@ -5725,7 +5725,7 @@ class ModelReadTest extends BaseModelTest {
$fullDebug = $this->db->fullDebug;
$this->db->fullDebug = true;
$TestModel->recursive = 6;
$result = $TestModel->find(array('CategoryThread.id' => 7));
$result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7)));
$expected = array(
'CategoryThread' => array(
@ -6007,12 +6007,12 @@ class ModelReadTest extends BaseModelTest {
function testConditionalNumerics() {
$this->loadFixtures('NumericArticle');
$NumericArticle = new NumericArticle();
$data = array('title' => '12345abcde');
$result = $NumericArticle->find($data);
$data = array('conditions' => array('title' => '12345abcde'));
$result = $NumericArticle->find('first', $data);
$this->assertTrue(!empty($result));
$data = array('title' => '12345');
$result = $NumericArticle->find($data);
$data = array('conditions' => array('title' => '12345'));
$result = $NumericArticle->find('first', $data);
$this->assertTrue(empty($result));
}

View file

@ -105,7 +105,7 @@ class ModelWriteTest extends BaseModelTest {
$result = $Article->save($data);
$this->assertFalse(empty($result));
$testResult = $Article->find(array('Article.title' => 'Test Title'));
$testResult = $Article->find('first', array('conditions' => array('Article.title' => 'Test Title')));
$this->assertEqual($testResult['Article']['title'], $data['Article']['title']);
$this->assertEqual($testResult['Article']['created'], '2008-01-01 00:00:00');
@ -1019,17 +1019,17 @@ class ModelWriteTest extends BaseModelTest {
$Article = new Article();
$result = $Article->save(Xml::build('<article title="test xml" user_id="5" />'));
$this->assertFalse(empty($result));
$results = $Article->find(array('Article.title' => 'test xml'));
$results = $Article->find('first', array('conditions' => array('Article.title' => 'test xml')));
$this->assertFalse(empty($results));
$result = $Article->save(Xml::build('<article><title>testing</title><user_id>6</user_id></article>'));
$this->assertFalse(empty($result));
$results = $Article->find(array('Article.title' => 'testing'));
$results = $Article->find('first', array('conditions' => array('Article.title' => 'testing')));
$this->assertFalse(empty($results));
$result = $Article->save(Xml::build('<article><title>testing with DOMDocument</title><user_id>7</user_id></article>', array('return' => 'domdocument')));
$this->assertFalse(empty($result));
$results = $Article->find(array('Article.title' => 'testing with DOMDocument'));
$results = $Article->find('first', array('conditions' => array('Article.title' => 'testing with DOMDocument')));
$this->assertFalse(empty($results));
}
@ -1111,7 +1111,7 @@ class ModelWriteTest extends BaseModelTest {
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1145,7 +1145,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1180,7 +1180,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1227,7 +1227,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1250,7 +1250,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1290,7 +1290,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1330,7 +1330,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1372,7 +1372,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1414,7 +1414,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -2987,10 +2987,6 @@ class ModelWriteTest extends BaseModelTest {
$db = ConnectionManager::create('mock_transaction', array(
'datasource' => 'MockTransactionDbo',
));
$db->expects($this->at(2))
->method('isInterfaceSupported')
->with('describe')
->will($this->returnValue(true));
$db->expects($this->once())
->method('describe')
@ -3026,8 +3022,6 @@ class ModelWriteTest extends BaseModelTest {
$db->columns = $testDb->columns;
$db->expects($this->once())->method('rollback');
$db->expects($this->any())->method('isInterfaceSupported')
->will($this->returnValue(true));
$db->expects($this->any())->method('describe')
->will($this->returnValue(array(
'id' => array('type' => 'integer'),