From c033df3218e0fbf8f38a950793f6d58082531f21 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 9 Aug 2013 09:56:33 +0200 Subject: [PATCH 01/26] Fixed duplication of Model's afterFind callback in HABTM relation and content of array passed to that callback [ticket 3970] --- app/Config/database.php.default | 79 ------------------------- lib/Cake/Model/Datasource/DboSource.php | 12 +++- 2 files changed, 9 insertions(+), 82 deletions(-) delete mode 100644 app/Config/database.php.default diff --git a/app/Config/database.php.default b/app/Config/database.php.default deleted file mode 100644 index e3f5985b5..000000000 --- a/app/Config/database.php.default +++ /dev/null @@ -1,79 +0,0 @@ - The name of a supported datasource; valid options are as follows: - * Database/Mysql - MySQL 4 & 5, - * Database/Sqlite - SQLite (PHP5 only), - * Database/Postgres - PostgreSQL 7 and higher, - * Database/Sqlserver - Microsoft SQL Server 2005 and higher - * - * You can add custom database datasources (or override existing datasources) by adding the - * appropriate file to app/Model/Datasource/Database. Datasources should be named 'MyDatasource.php', - * - * - * persistent => true / false - * Determines whether or not the database should use a persistent connection - * - * host => - * the host you connect to the database. To add a socket or port number, use 'port' => # - * - * prefix => - * Uses the given prefix for all the tables in this database. This setting can be overridden - * on a per-table basis with the Model::$tablePrefix property. - * - * schema => - * For Postgres/Sqlserver specifies which schema you would like to use the tables in. Postgres defaults to 'public'. For Sqlserver, it defaults to empty and use - * the connected user's default schema (typically 'dbo'). - * - * encoding => - * For MySQL, Postgres specifies the character encoding to use when connecting to the - * database. Uses database default not specified. - * - * unix_socket => - * For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port` - */ -class DATABASE_CONFIG { - - public $default = array( - 'datasource' => 'Database/Mysql', - 'persistent' => false, - 'host' => 'localhost', - 'login' => 'user', - 'password' => 'password', - 'database' => 'database_name', - 'prefix' => '', - //'encoding' => 'utf8', - ); - - public $test = array( - 'datasource' => 'Database/Mysql', - 'persistent' => false, - 'host' => 'localhost', - 'login' => 'user', - 'password' => 'password', - 'database' => 'test_database_name', - 'prefix' => '', - //'encoding' => 'utf8', - ); -} diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index abdad2437..120ab17e0 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1112,7 +1112,7 @@ class DboSource extends DataSource { $db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack); unset($db); - if ($type === 'hasMany') { + if ($type === 'hasMany' || $type === 'hasAndBelongsToMany') { $filtered[] = $assoc; } } @@ -1138,7 +1138,10 @@ class DboSource extends DataSource { * @return array Array of results that have been filtered through $model->afterFind */ protected function _filterResults(&$results, Model $model, $filtered = array()) { - $current = reset($results); + if (!is_array($results)) { + return array(); + } + $current = reset($results); if (!is_array($current)) { return array(); } @@ -1252,6 +1255,9 @@ class DboSource extends DataSource { } else { $fetch = null; } + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + $this->_filterResults($fetch, $model); + } } $modelAlias = $model->alias; @@ -1312,7 +1318,7 @@ class DboSource extends DataSource { } else { $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin); } - if (isset($row[$association])) { + if (isset($row[$association]) && $type !== 'hasAndBelongsToMany') { $row[$association] = $linkModel->afterFind($row[$association], false); } } else { From faff191ccaf31928745198cb00cf039bf9473e7f Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 9 Aug 2013 10:19:35 +0200 Subject: [PATCH 02/26] Problems with files :/ --- app/Config/database.php.default | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 app/Config/database.php.default diff --git a/app/Config/database.php.default b/app/Config/database.php.default new file mode 100644 index 000000000..e3f5985b5 --- /dev/null +++ b/app/Config/database.php.default @@ -0,0 +1,79 @@ + The name of a supported datasource; valid options are as follows: + * Database/Mysql - MySQL 4 & 5, + * Database/Sqlite - SQLite (PHP5 only), + * Database/Postgres - PostgreSQL 7 and higher, + * Database/Sqlserver - Microsoft SQL Server 2005 and higher + * + * You can add custom database datasources (or override existing datasources) by adding the + * appropriate file to app/Model/Datasource/Database. Datasources should be named 'MyDatasource.php', + * + * + * persistent => true / false + * Determines whether or not the database should use a persistent connection + * + * host => + * the host you connect to the database. To add a socket or port number, use 'port' => # + * + * prefix => + * Uses the given prefix for all the tables in this database. This setting can be overridden + * on a per-table basis with the Model::$tablePrefix property. + * + * schema => + * For Postgres/Sqlserver specifies which schema you would like to use the tables in. Postgres defaults to 'public'. For Sqlserver, it defaults to empty and use + * the connected user's default schema (typically 'dbo'). + * + * encoding => + * For MySQL, Postgres specifies the character encoding to use when connecting to the + * database. Uses database default not specified. + * + * unix_socket => + * For MySQL to connect via socket specify the `unix_socket` parameter instead of `host` and `port` + */ +class DATABASE_CONFIG { + + public $default = array( + 'datasource' => 'Database/Mysql', + 'persistent' => false, + 'host' => 'localhost', + 'login' => 'user', + 'password' => 'password', + 'database' => 'database_name', + 'prefix' => '', + //'encoding' => 'utf8', + ); + + public $test = array( + 'datasource' => 'Database/Mysql', + 'persistent' => false, + 'host' => 'localhost', + 'login' => 'user', + 'password' => 'password', + 'database' => 'test_database_name', + 'prefix' => '', + //'encoding' => 'utf8', + ); +} From 3855c0690e43a9e01f0d29961ac5314f45c22420 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 9 Aug 2013 10:26:44 +0200 Subject: [PATCH 03/26] Fixed tabing formating --- lib/Cake/Model/Datasource/DboSource.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 120ab17e0..9672b4512 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1139,9 +1139,9 @@ class DboSource extends DataSource { */ protected function _filterResults(&$results, Model $model, $filtered = array()) { if (!is_array($results)) { - return array(); - } - $current = reset($results); + return array(); + } + $current = reset($results); if (!is_array($current)) { return array(); } @@ -1255,7 +1255,7 @@ class DboSource extends DataSource { } else { $fetch = null; } - if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { $this->_filterResults($fetch, $model); } } From 2655d16c13cc1995d0df35753af4d856e01909f7 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 9 Aug 2013 11:17:12 +0200 Subject: [PATCH 04/26] Fixed tabbing in some places --- lib/Cake/Model/Datasource/DboSource.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 9672b4512..4f749cb46 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1139,9 +1139,9 @@ class DboSource extends DataSource { */ protected function _filterResults(&$results, Model $model, $filtered = array()) { if (!is_array($results)) { - return array(); - } - $current = reset($results); + return array(); + } + $current = reset($results); if (!is_array($current)) { return array(); } @@ -1255,7 +1255,7 @@ class DboSource extends DataSource { } else { $fetch = null; } - if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { $this->_filterResults($fetch, $model); } } From 74eb32696a88abc4dfcc0e6b2fa4108f0e78d020 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 9 Aug 2013 11:51:19 +0200 Subject: [PATCH 05/26] Some more space / tabs issues [Travis PHPCS=1 fail] --- lib/Cake/Model/Datasource/DboSource.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 4f749cb46..1ba477afb 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1139,9 +1139,9 @@ class DboSource extends DataSource { */ protected function _filterResults(&$results, Model $model, $filtered = array()) { if (!is_array($results)) { - return array(); - } - $current = reset($results); + return array(); + } + $current = reset($results); if (!is_array($current)) { return array(); } @@ -1255,7 +1255,7 @@ class DboSource extends DataSource { } else { $fetch = null; } - if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { $this->_filterResults($fetch, $model); } } From 8e40a3a3d3c82cd3ae06924559b21e337364a603 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 09:29:14 +0200 Subject: [PATCH 06/26] Added some tests for related models afterFind callback --- lib/Cake/Model/Datasource/DboSource.php | 6191 ++++--- lib/Cake/Test/Case/Model/ModelReadTest.php | 15446 ++++++++-------- lib/Cake/Test/Case/Model/ModelTestBase.php | 126 +- lib/Cake/Test/Case/Model/models.php | 6501 +++---- .../Fixture/ModelHabtmRelationFixture.php | 52 + lib/Cake/Test/Fixture/ModelRelatedFixture.php | 50 + .../Fixture/ModelWithRelationsFixture.php | 50 + 7 files changed, 14407 insertions(+), 14009 deletions(-) create mode 100644 lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php create mode 100644 lib/Cake/Test/Fixture/ModelRelatedFixture.php create mode 100644 lib/Cake/Test/Fixture/ModelWithRelationsFixture.php diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 9672b4512..2b72f30fc 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1,4 +1,5 @@ 'primary', 'MUL' => 'index', 'UNI' => 'unique'); + /** + * index definition, standard cake, primary, index, unique + * + * @var array + */ + public $index = array('PRI' => 'primary', 'MUL' => 'index', 'UNI' => 'unique'); -/** - * Database keyword used to assign aliases to identifiers. - * - * @var string - */ - public $alias = 'AS '; + /** + * Database keyword used to assign aliases to identifiers. + * + * @var string + */ + public $alias = 'AS '; -/** - * Caches result from query parsing operations. Cached results for both DboSource::name() and - * DboSource::conditions() will be stored here. Method caching uses `md5()`. If you have - * problems with collisions, set DboSource::$cacheMethods to false. - * - * @var array - */ - public static $methodCache = array(); + /** + * Caches result from query parsing operations. Cached results for both DboSource::name() and + * DboSource::conditions() will be stored here. Method caching uses `md5()`. If you have + * problems with collisions, set DboSource::$cacheMethods to false. + * + * @var array + */ + public static $methodCache = array(); -/** - * Whether or not to cache the results of DboSource::name() and DboSource::conditions() - * into the memory cache. Set to false to disable the use of the memory cache. - * - * @var boolean - */ - public $cacheMethods = true; + /** + * Whether or not to cache the results of DboSource::name() and DboSource::conditions() + * into the memory cache. Set to false to disable the use of the memory cache. + * + * @var boolean + */ + public $cacheMethods = true; -/** - * Flag to support nested transactions. If it is set to false, you will be able to use - * the transaction methods (begin/commit/rollback), but just the global transaction will - * be executed. - * - * @var boolean - */ - public $useNestedTransactions = false; + /** + * Flag to support nested transactions. If it is set to false, you will be able to use + * the transaction methods (begin/commit/rollback), but just the global transaction will + * be executed. + * + * @var boolean + */ + public $useNestedTransactions = false; -/** - * Print full query debug info? - * - * @var boolean - */ - public $fullDebug = false; + /** + * Print full query debug info? + * + * @var boolean + */ + public $fullDebug = false; -/** - * String to hold how many rows were affected by the last SQL operation. - * - * @var string - */ - public $affected = null; + /** + * String to hold how many rows were affected by the last SQL operation. + * + * @var string + */ + public $affected = null; -/** - * Number of rows in current resultset - * - * @var integer - */ - public $numRows = null; + /** + * Number of rows in current resultset + * + * @var integer + */ + public $numRows = null; -/** - * Time the last query took - * - * @var integer - */ - public $took = null; + /** + * Time the last query took + * + * @var integer + */ + public $took = null; -/** - * Result - * - * @var array - */ - protected $_result = null; + /** + * Result + * + * @var array + */ + protected $_result = null; -/** - * Queries count. - * - * @var integer - */ - protected $_queriesCnt = 0; + /** + * Queries count. + * + * @var integer + */ + protected $_queriesCnt = 0; -/** - * Total duration of all queries. - * - * @var integer - */ - protected $_queriesTime = null; + /** + * Total duration of all queries. + * + * @var integer + */ + protected $_queriesTime = null; -/** - * Log of queries executed by this DataSource - * - * @var array - */ - protected $_queriesLog = array(); + /** + * Log of queries executed by this DataSource + * + * @var array + */ + protected $_queriesLog = array(); -/** - * Maximum number of items in query log - * - * This is to prevent query log taking over too much memory. - * - * @var integer Maximum number of queries in the queries log. - */ - protected $_queriesLogMax = 200; + /** + * Maximum number of items in query log + * + * This is to prevent query log taking over too much memory. + * + * @var integer Maximum number of queries in the queries log. + */ + protected $_queriesLogMax = 200; -/** - * Caches serialized results of executed queries - * - * @var array Cache of results from executed sql queries. - */ - protected $_queryCache = array(); + /** + * Caches serialized results of executed queries + * + * @var array Cache of results from executed sql queries. + */ + protected $_queryCache = array(); -/** - * A reference to the physical connection of this DataSource - * - * @var array - */ - protected $_connection = null; + /** + * A reference to the physical connection of this DataSource + * + * @var array + */ + protected $_connection = null; -/** - * The DataSource configuration key name - * - * @var string - */ - public $configKeyName = null; + /** + * The DataSource configuration key name + * + * @var string + */ + public $configKeyName = null; -/** - * The starting character that this DataSource uses for quoted identifiers. - * - * @var string - */ - public $startQuote = null; + /** + * The starting character that this DataSource uses for quoted identifiers. + * + * @var string + */ + public $startQuote = null; -/** - * The ending character that this DataSource uses for quoted identifiers. - * - * @var string - */ - public $endQuote = null; + /** + * The ending character that this DataSource uses for quoted identifiers. + * + * @var string + */ + public $endQuote = null; -/** - * The set of valid SQL operations usable in a WHERE statement - * - * @var array - */ - protected $_sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', 'regexp', 'similar to'); + /** + * The set of valid SQL operations usable in a WHERE statement + * + * @var array + */ + protected $_sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', 'regexp', 'similar to'); -/** - * Indicates the level of nested transactions - * - * @var integer - */ - protected $_transactionNesting = 0; + /** + * Indicates the level of nested transactions + * + * @var integer + */ + protected $_transactionNesting = 0; -/** - * Default fields that are used by the DBO - * - * @var array - */ - protected $_queryDefaults = array( - 'conditions' => array(), - 'fields' => null, - 'table' => null, - 'alias' => null, - 'order' => null, - 'limit' => null, - 'joins' => array(), - 'group' => null, - 'offset' => null + /** + * Default fields that are used by the DBO + * + * @var array + */ + protected $_queryDefaults = array( + 'conditions' => array(), + 'fields' => null, + 'table' => null, + 'alias' => null, + 'order' => null, + 'limit' => null, + 'joins' => array(), + 'group' => null, + 'offset' => null + ); + + /** + * Separator string for virtualField composition + * + * @var string + */ + public $virtualFieldSeparator = '__'; + + /** + * List of table engine specific parameters used on table creating + * + * @var array + */ + public $tableParameters = array(); + + /** + * List of engine specific additional field parameters used on table creating + * + * @var array + */ + public $fieldParameters = array(); + + /** + * Indicates whether there was a change on the cached results on the methods of this class + * This will be used for storing in a more persistent cache + * + * @var boolean + */ + protected $_methodCacheChange = false; + + /** + * Constructor + * + * @param array $config Array of configuration information for the Datasource. + * @param boolean $autoConnect Whether or not the datasource should automatically connect. + * @throws MissingConnectionException when a connection cannot be made. + */ + public function __construct($config = null, $autoConnect = true) { + if (!isset($config['prefix'])) { + $config['prefix'] = ''; + } + parent::__construct($config); + $this->fullDebug = Configure::read('debug') > 1; + if (!$this->enabled()) { + throw new MissingConnectionException(array( + 'class' => get_class($this), + 'message' => __d('cake_dev', 'Selected driver is not enabled'), + 'enabled' => false + )); + } + if ($autoConnect) { + $this->connect(); + } + } + + /** + * Reconnects to database server with optional new settings + * + * @param array $config An array defining the new configuration settings + * @return boolean True on success, false on failure + */ + public function reconnect($config = array()) { + $this->disconnect(); + $this->setConfig($config); + $this->_sources = null; + + return $this->connect(); + } + + /** + * Disconnects from database. + * + * @return boolean Always true + */ + public function disconnect() { + if ($this->_result instanceof PDOStatement) { + $this->_result->closeCursor(); + } + unset($this->_connection); + $this->connected = false; + return true; + } + + /** + * Get the underlying connection object. + * + * @return PDO + */ + public function getConnection() { + return $this->_connection; + } + + /** + * Gets the version string of the database server + * + * @return string The database version + */ + public function getVersion() { + return $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION); + } + + /** + * Returns a quoted and escaped string of $data for use in an SQL statement. + * + * @param string $data String to be prepared for use in an SQL statement + * @param string $column The column into which this data will be inserted + * @return string Quoted and escaped data + */ + public function value($data, $column = null) { + if (is_array($data) && !empty($data)) { + return array_map( + array(&$this, 'value'), $data, array_fill(0, count($data), $column) + ); + } elseif (is_object($data) && isset($data->type, $data->value)) { + if ($data->type === 'identifier') { + return $this->name($data->value); + } elseif ($data->type === 'expression') { + return $data->value; + } + } elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { + return $data; + } + + if ($data === null || (is_array($data) && empty($data))) { + return 'NULL'; + } + + if (empty($column)) { + $column = $this->introspectType($data); + } + + switch ($column) { + case 'binary': + return $this->_connection->quote($data, PDO::PARAM_LOB); + case 'boolean': + return $this->_connection->quote($this->boolean($data, true), PDO::PARAM_BOOL); + case 'string': + case 'text': + return $this->_connection->quote($data, PDO::PARAM_STR); + default: + if ($data === '') { + return 'NULL'; + } + if (is_float($data)) { + return str_replace(',', '.', strval($data)); + } + if ((is_int($data) || $data === '0') || ( + is_numeric($data) && strpos($data, ',') === false && + $data[0] != '0' && strpos($data, 'e') === false) + ) { + return $data; + } + return $this->_connection->quote($data); + } + } + + /** + * Returns an object to represent a database identifier in a query. Expression objects + * are not sanitized or escaped. + * + * @param string $identifier A SQL expression to be used as an identifier + * @return stdClass An object representing a database identifier to be used in a query + */ + public function identifier($identifier) { + $obj = new stdClass(); + $obj->type = 'identifier'; + $obj->value = $identifier; + return $obj; + } + + /** + * Returns an object to represent a database expression in a query. Expression objects + * are not sanitized or escaped. + * + * @param string $expression An arbitrary SQL expression to be inserted into a query. + * @return stdClass An object representing a database expression to be used in a query + */ + public function expression($expression) { + $obj = new stdClass(); + $obj->type = 'expression'; + $obj->value = $expression; + return $obj; + } + + /** + * Executes given SQL statement. + * + * @param string $sql SQL statement + * @param array $params Additional options for the query. + * @return boolean + */ + public function rawQuery($sql, $params = array()) { + $this->took = $this->numRows = false; + return $this->execute($sql, $params); + } + + /** + * Queries the database with given SQL statement, and obtains some metadata about the result + * (rows affected, timing, any errors, number of rows in resultset). The query is also logged. + * If Configure::read('debug') is set, the log is shown all the time, else it is only shown on errors. + * + * ### Options + * + * - log - Whether or not the query should be logged to the memory log. + * + * @param string $sql SQL statement + * @param array $options + * @param array $params values to be bound to the query + * @return mixed Resource or object representing the result set, or false on failure + */ + public function execute($sql, $options = array(), $params = array()) { + $options += array('log' => $this->fullDebug); + + $t = microtime(true); + $this->_result = $this->_execute($sql, $params); + + if ($options['log']) { + $this->took = round((microtime(true) - $t) * 1000, 0); + $this->numRows = $this->affected = $this->lastAffected(); + $this->logQuery($sql, $params); + } + + return $this->_result; + } + + /** + * Executes given SQL statement. + * + * @param string $sql SQL statement + * @param array $params list of params to be bound to query + * @param array $prepareOptions Options to be used in the prepare statement + * @return mixed PDOStatement if query executes with no problem, true as the result of a successful, false on error + * query returning no rows, such as a CREATE statement, false otherwise + * @throws PDOException + */ + protected function _execute($sql, $params = array(), $prepareOptions = array()) { + $sql = trim($sql); + if (preg_match('/^(?:CREATE|ALTER|DROP)\s+(?:TABLE|INDEX)/i', $sql)) { + $statements = array_filter(explode(';', $sql)); + if (count($statements) > 1) { + $result = array_map(array($this, '_execute'), $statements); + return array_search(false, $result) === false; + } + } + + try { + $query = $this->_connection->prepare($sql, $prepareOptions); + $query->setFetchMode(PDO::FETCH_LAZY); + if (!$query->execute($params)) { + $this->_results = $query; + $query->closeCursor(); + return false; + } + if (!$query->columnCount()) { + $query->closeCursor(); + if (!$query->rowCount()) { + return true; + } + } + return $query; + } catch (PDOException $e) { + if (isset($query->queryString)) { + $e->queryString = $query->queryString; + } else { + $e->queryString = $sql; + } + throw $e; + } + } + + /** + * Returns a formatted error message from previous database operation. + * + * @param PDOStatement $query the query to extract the error from if any + * @return string Error message with error number + */ + public function lastError(PDOStatement $query = null) { + if ($query) { + $error = $query->errorInfo(); + } else { + $error = $this->_connection->errorInfo(); + } + if (empty($error[2])) { + return null; + } + return $error[1] . ': ' . $error[2]; + } + + /** + * Returns number of affected rows in previous database operation. If no previous operation exists, + * this returns false. + * + * @param mixed $source + * @return integer Number of affected rows + */ + public function lastAffected($source = null) { + if ($this->hasResult()) { + return $this->_result->rowCount(); + } + return 0; + } + + /** + * Returns number of rows in previous resultset. If no previous resultset exists, + * this returns false. + * + * @param mixed $source Not used + * @return integer Number of rows in resultset + */ + public function lastNumRows($source = null) { + return $this->lastAffected(); + } + + /** + * DataSource Query abstraction + * + * @return resource Result resource identifier. + */ + public function query() { + $args = func_get_args(); + $fields = null; + $order = null; + $limit = null; + $page = null; + $recursive = null; + + if (count($args) === 1) { + return $this->fetchAll($args[0]); + } elseif (count($args) > 1 && (strpos($args[0], 'findBy') === 0 || strpos($args[0], 'findAllBy') === 0)) { + $params = $args[1]; + + if (substr($args[0], 0, 6) === 'findBy') { + $all = false; + $field = Inflector::underscore(substr($args[0], 6)); + } else { + $all = true; + $field = Inflector::underscore(substr($args[0], 9)); + } + + $or = (strpos($field, '_or_') !== false); + if ($or) { + $field = explode('_or_', $field); + } else { + $field = explode('_and_', $field); + } + $off = count($field) - 1; + + if (isset($params[1 + $off])) { + $fields = $params[1 + $off]; + } + + if (isset($params[2 + $off])) { + $order = $params[2 + $off]; + } + + if (!array_key_exists(0, $params)) { + return false; + } + + $c = 0; + $conditions = array(); + + foreach ($field as $f) { + $conditions[$args[2]->alias . '.' . $f] = $params[$c++]; + } + + if ($or) { + $conditions = array('OR' => $conditions); + } + + if ($all) { + if (isset($params[3 + $off])) { + $limit = $params[3 + $off]; + } + + if (isset($params[4 + $off])) { + $page = $params[4 + $off]; + } + + if (isset($params[5 + $off])) { + $recursive = $params[5 + $off]; + } + return $args[2]->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive')); + } + if (isset($params[3 + $off])) { + $recursive = $params[3 + $off]; + } + return $args[2]->find('first', compact('conditions', 'fields', 'order', 'recursive')); + } + if (isset($args[1]) && $args[1] === true) { + return $this->fetchAll($args[0], true); + } elseif (isset($args[1]) && !is_array($args[1])) { + return $this->fetchAll($args[0], false); + } elseif (isset($args[1]) && is_array($args[1])) { + if (isset($args[2])) { + $cache = $args[2]; + } else { + $cache = true; + } + return $this->fetchAll($args[0], $args[1], array('cache' => $cache)); + } + } + + /** + * Returns a row from current resultset as an array + * + * @param string $sql Some SQL to be executed. + * @return array The fetched row as an array + */ + public function fetchRow($sql = null) { + if (is_string($sql) && strlen($sql) > 5 && !$this->execute($sql)) { + return null; + } + + if ($this->hasResult()) { + $this->resultSet($this->_result); + $resultRow = $this->fetchResult(); + if (isset($resultRow[0])) { + $this->fetchVirtualField($resultRow); + } + return $resultRow; + } + return null; + } + + /** + * Returns an array of all result rows for a given SQL query. + * Returns false if no rows matched. + * + * ### Options + * + * - `cache` - Returns the cached version of the query, if exists and stores the result in cache. + * This is a non-persistent cache, and only lasts for a single request. This option + * defaults to true. If you are directly calling this method, you can disable caching + * by setting $options to `false` + * + * @param string $sql SQL statement + * @param array $params parameters to be bound as values for the SQL statement + * @param array $options additional options for the query. + * @return boolean|array Array of resultset rows, or false if no rows matched + */ + public function fetchAll($sql, $params = array(), $options = array()) { + if (is_string($options)) { + $options = array('modelName' => $options); + } + if (is_bool($params)) { + $options['cache'] = $params; + $params = array(); + } + $options += array('cache' => true); + $cache = $options['cache']; + if ($cache && ($cached = $this->getQueryCache($sql, $params)) !== false) { + return $cached; + } + if ($result = $this->execute($sql, array(), $params)) { + $out = array(); + + if ($this->hasResult()) { + $first = $this->fetchRow(); + if ($first) { + $out[] = $first; + } + while ($item = $this->fetchResult()) { + if (isset($item[0])) { + $this->fetchVirtualField($item); + } + $out[] = $item; + } + } + + if (!is_bool($result) && $cache) { + $this->_writeQueryCache($sql, $out, $params); + } + + if (empty($out) && is_bool($this->_result)) { + return $this->_result; + } + return $out; + } + return false; + } + + /** + * Fetches the next row from the current result set + * + * @return boolean + */ + public function fetchResult() { + return false; + } + + /** + * Modifies $result array to place virtual fields in model entry where they belongs to + * + * @param array $result Reference to the fetched row + * @return void + */ + public function fetchVirtualField(&$result) { + if (isset($result[0]) && is_array($result[0])) { + foreach ($result[0] as $field => $value) { + if (strpos($field, $this->virtualFieldSeparator) === false) { + continue; + } + list($alias, $virtual) = explode($this->virtualFieldSeparator, $field); + + if (!ClassRegistry::isKeySet($alias)) { + return; + } + $model = ClassRegistry::getObject($alias); + if ($model->isVirtualField($virtual)) { + $result[$alias][$virtual] = $value; + unset($result[0][$field]); + } + } + if (empty($result[0])) { + unset($result[0]); + } + } + } + + /** + * Returns a single field of the first of query results for a given SQL query, or false if empty. + * + * @param string $name Name of the field + * @param string $sql SQL query + * @return mixed Value of field read. + */ + public function field($name, $sql) { + $data = $this->fetchRow($sql); + if (empty($data[$name])) { + return false; + } + return $data[$name]; + } + + /** + * Empties the method caches. + * These caches are used by DboSource::name() and DboSource::conditions() + * + * @return void + */ + public function flushMethodCache() { + $this->_methodCacheChange = true; + self::$methodCache = array(); + } + + /** + * Cache a value into the methodCaches. Will respect the value of DboSource::$cacheMethods. + * Will retrieve a value from the cache if $value is null. + * + * If caching is disabled and a write is attempted, the $value will be returned. + * A read will either return the value or null. + * + * @param string $method Name of the method being cached. + * @param string $key The key name for the cache operation. + * @param mixed $value The value to cache into memory. + * @return mixed Either null on failure, or the value if its set. + */ + public function cacheMethod($method, $key, $value = null) { + if ($this->cacheMethods === false) { + return $value; + } + if (empty(self::$methodCache)) { + self::$methodCache = Cache::read('method_cache', '_cake_core_'); + } + if ($value === null) { + return (isset(self::$methodCache[$method][$key])) ? self::$methodCache[$method][$key] : null; + } + $this->_methodCacheChange = true; + return self::$methodCache[$method][$key] = $value; + } + + /** + * Returns a quoted name of $data for use in an SQL statement. + * Strips fields out of SQL functions before quoting. + * + * Results of this method are stored in a memory cache. This improves performance, but + * because the method uses a hashing algorithm it can have collisions. + * Setting DboSource::$cacheMethods to false will disable the memory cache. + * + * @param mixed $data Either a string with a column to quote. An array of columns to quote or an + * object from DboSource::expression() or DboSource::identifier() + * @return string SQL field + */ + public function name($data) { + if (is_object($data) && isset($data->type)) { + return $data->value; + } + if ($data === '*') { + return '*'; + } + if (is_array($data)) { + foreach ($data as $i => $dataItem) { + $data[$i] = $this->name($dataItem); + } + return $data; + } + $cacheKey = md5($this->startQuote . $data . $this->endQuote); + if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) { + return $return; + } + $data = trim($data); + if (preg_match('/^[\w-]+(?:\.[^ \*]*)*$/', $data)) { // string, string.string + if (strpos($data, '.') === false) { // string + return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote); + } + $items = explode('.', $data); + return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote + ); + } + if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.* + return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data) + ); + } + if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions + return $this->cacheMethod(__FUNCTION__, $cacheKey, $matches[1] . '(' . $this->name($matches[2]) . ')' + ); + } + if ( + preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/i', $data, $matches + )) { + return $this->cacheMethod( + __FUNCTION__, $cacheKey, preg_replace( + '/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]) + ) + ); + } + if (preg_match('/^[\w-_\s]*[\w-_]+/', $data)) { + return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote); + } + return $this->cacheMethod(__FUNCTION__, $cacheKey, $data); + } + + /** + * Checks if the source is connected to the database. + * + * @return boolean True if the database is connected, else false + */ + public function isConnected() { + return $this->connected; + } + + /** + * Checks if the result is valid + * + * @return boolean True if the result is valid else false + */ + public function hasResult() { + return is_a($this->_result, 'PDOStatement'); + } + + /** + * Get the query log as an array. + * + * @param boolean $sorted Get the queries sorted by time taken, defaults to false. + * @param boolean $clear If True the existing log will cleared. + * @return array Array of queries run as an array + */ + public function getLog($sorted = false, $clear = true) { + if ($sorted) { + $log = sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC); + } else { + $log = $this->_queriesLog; + } + if ($clear) { + $this->_queriesLog = array(); + } + return array('log' => $log, 'count' => $this->_queriesCnt, 'time' => $this->_queriesTime); + } + + /** + * Outputs the contents of the queries log. If in a non-CLI environment the sql_log element + * will be rendered and output. If in a CLI environment, a plain text log is generated. + * + * @param boolean $sorted Get the queries sorted by time taken, defaults to false. + * @return void + */ + public function showLog($sorted = false) { + $log = $this->getLog($sorted, false); + if (empty($log['log'])) { + return; + } + if (PHP_SAPI !== 'cli') { + $controller = null; + $View = new View($controller, false); + $View->set('logs', array($this->configKeyName => $log)); + echo $View->element('sql_dump', array('_forced_from_dbo_' => true)); + } else { + foreach ($log['log'] as $k => $i) { + print (($k + 1) . ". {$i['query']}\n"); + } + } + } + + /** + * Log given SQL query. + * + * @param string $sql SQL statement + * @param array $params Values binded to the query (prepared statements) + * @return void + */ + public function logQuery($sql, $params = array()) { + $this->_queriesCnt++; + $this->_queriesTime += $this->took; + $this->_queriesLog[] = array( + 'query' => $sql, + 'params' => $params, + 'affected' => $this->affected, + 'numRows' => $this->numRows, + 'took' => $this->took + ); + if (count($this->_queriesLog) > $this->_queriesLogMax) { + array_shift($this->_queriesLog); + } + } + + /** + * Gets full table name including prefix + * + * @param Model|string $model Either a Model object or a string table name. + * @param boolean $quote Whether you want the table name quoted. + * @param boolean $schema Whether you want the schema name included. + * @return string Full quoted table name + */ + public function fullTableName($model, $quote = true, $schema = true) { + if (is_object($model)) { + $schemaName = $model->schemaName; + $table = $model->tablePrefix . $model->table; + } elseif (!empty($this->config['prefix']) && strpos($model, $this->config['prefix']) !== 0) { + $table = $this->config['prefix'] . strval($model); + } else { + $table = strval($model); + } + if ($schema && !isset($schemaName)) { + $schemaName = $this->getSchemaName(); + } + + if ($quote) { + if ($schema && !empty($schemaName)) { + if (false == strstr($table, '.')) { + return $this->name($schemaName) . '.' . $this->name($table); + } + } + return $this->name($table); + } + if ($schema && !empty($schemaName)) { + if (false == strstr($table, '.')) { + return $schemaName . '.' . $table; + } + } + return $table; + } + + /** + * The "C" in CRUD + * + * Creates new records in the database. + * + * @param Model $model Model object that the record is for. + * @param array $fields An array of field names to insert. If null, $model->data will be + * used to generate field names. + * @param array $values An array of values with keys matching the fields. If null, $model->data will + * be used to generate values. + * @return boolean Success + */ + public function create(Model $model, $fields = null, $values = null) { + $id = null; + + if (!$fields) { + unset($fields, $values); + $fields = array_keys($model->data); + $values = array_values($model->data); + } + $count = count($fields); + + for ($i = 0; $i < $count; $i++) { + $valueInsert[] = $this->value($values[$i], $model->getColumnType($fields[$i])); + $fieldInsert[] = $this->name($fields[$i]); + if ($fields[$i] == $model->primaryKey) { + $id = $values[$i]; + } + } + $query = array( + 'table' => $this->fullTableName($model), + 'fields' => implode(', ', $fieldInsert), + 'values' => implode(', ', $valueInsert) ); -/** - * Separator string for virtualField composition - * - * @var string - */ - public $virtualFieldSeparator = '__'; + if ($this->execute($this->renderStatement('create', $query))) { + if (empty($id)) { + $id = $this->lastInsertId($this->fullTableName($model, false, false), $model->primaryKey); + } + $model->setInsertID($id); + $model->id = $id; + return true; + } + $model->onError(); + return false; + } -/** - * List of table engine specific parameters used on table creating - * - * @var array - */ - public $tableParameters = array(); + /** + * The "R" in CRUD + * + * Reads record(s) from the database. + * + * @param Model $model A Model object that the query is for. + * @param array $queryData An array of queryData information containing keys similar to Model::find() + * @param integer $recursive Number of levels of association + * @return mixed boolean false on error/failure. An array of results on success. + */ + public function read(Model $model, $queryData = array(), $recursive = null) { + $queryData = $this->_scrubQueryData($queryData); -/** - * List of engine specific additional field parameters used on table creating - * - * @var array - */ - public $fieldParameters = array(); + $null = null; + $array = array('callbacks' => $queryData['callbacks']); + $linkedModels = array(); + $bypass = false; -/** - * Indicates whether there was a change on the cached results on the methods of this class - * This will be used for storing in a more persistent cache - * - * @var boolean - */ - protected $_methodCacheChange = false; - -/** - * Constructor - * - * @param array $config Array of configuration information for the Datasource. - * @param boolean $autoConnect Whether or not the datasource should automatically connect. - * @throws MissingConnectionException when a connection cannot be made. - */ - public function __construct($config = null, $autoConnect = true) { - if (!isset($config['prefix'])) { - $config['prefix'] = ''; - } - parent::__construct($config); - $this->fullDebug = Configure::read('debug') > 1; - if (!$this->enabled()) { - throw new MissingConnectionException(array( - 'class' => get_class($this), - 'message' => __d('cake_dev', 'Selected driver is not enabled'), - 'enabled' => false - )); - } - if ($autoConnect) { - $this->connect(); - } + if ($recursive === null && isset($queryData['recursive'])) { + $recursive = $queryData['recursive']; } -/** - * Reconnects to database server with optional new settings - * - * @param array $config An array defining the new configuration settings - * @return boolean True on success, false on failure - */ - public function reconnect($config = array()) { - $this->disconnect(); - $this->setConfig($config); - $this->_sources = null; - - return $this->connect(); + if (!is_null($recursive)) { + $_recursive = $model->recursive; + $model->recursive = $recursive; } -/** - * Disconnects from database. - * - * @return boolean Always true - */ - public function disconnect() { - if ($this->_result instanceof PDOStatement) { - $this->_result->closeCursor(); + if (!empty($queryData['fields'])) { + $bypass = true; + $queryData['fields'] = $this->fields($model, null, $queryData['fields']); + } else { + $queryData['fields'] = $this->fields($model); + } + + $_associations = $model->associations(); + + if ($model->recursive == -1) { + $_associations = array(); + } elseif ($model->recursive === 0) { + unset($_associations[2], $_associations[3]); + } + + foreach ($_associations as $type) { + foreach ($model->{$type} as $assoc => $assocData) { + $linkModel = $model->{$assoc}; + $external = isset($assocData['external']); + + $linkModel->getDataSource(); + if ($model->useDbConfig === $linkModel->useDbConfig) { + if ($bypass) { + $assocData['fields'] = false; + } + if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) { + $linkedModels[$type . '/' . $assoc] = true; + } } - unset($this->_connection); - $this->connected = false; - return true; + } } -/** - * Get the underlying connection object. - * - * @return PDO - */ - public function getConnection() { - return $this->_connection; + $query = trim($this->generateAssociationQuery($model, null, null, null, null, $queryData, false, $null)); + + $resultSet = $this->fetchAll($query, $model->cacheQueries); + + if ($resultSet === false) { + $model->onError(); + return false; } -/** - * Gets the version string of the database server - * - * @return string The database version - */ - public function getVersion() { - return $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION); + $filtered = array(); + + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + $filtered = $this->_filterResults($resultSet, $model); } -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @param string $column The column into which this data will be inserted - * @return string Quoted and escaped data - */ - public function value($data, $column = null) { - if (is_array($data) && !empty($data)) { - return array_map( - array(&$this, 'value'), - $data, array_fill(0, count($data), $column) - ); - } elseif (is_object($data) && isset($data->type, $data->value)) { - if ($data->type === 'identifier') { - return $this->name($data->value); - } elseif ($data->type === 'expression') { - return $data->value; - } - } elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) { - return $data; - } + if ($model->recursive > -1) { + $joined = array(); + if (isset($queryData['joins'][0]['alias'])) { + $joined[$model->alias] = (array) Hash::extract($queryData['joins'], '{n}.alias'); + } + foreach ($_associations as $type) { + foreach ($model->{$type} as $assoc => $assocData) { + $linkModel = $model->{$assoc}; - if ($data === null || (is_array($data) && empty($data))) { - return 'NULL'; - } - - if (empty($column)) { - $column = $this->introspectType($data); - } - - switch ($column) { - case 'binary': - return $this->_connection->quote($data, PDO::PARAM_LOB); - case 'boolean': - return $this->_connection->quote($this->boolean($data, true), PDO::PARAM_BOOL); - case 'string': - case 'text': - return $this->_connection->quote($data, PDO::PARAM_STR); - default: - if ($data === '') { - return 'NULL'; - } - if (is_float($data)) { - return str_replace(',', '.', strval($data)); - } - if ((is_int($data) || $data === '0') || ( - is_numeric($data) && strpos($data, ',') === false && - $data[0] != '0' && strpos($data, 'e') === false) - ) { - return $data; - } - return $this->_connection->quote($data); - } - } - -/** - * Returns an object to represent a database identifier in a query. Expression objects - * are not sanitized or escaped. - * - * @param string $identifier A SQL expression to be used as an identifier - * @return stdClass An object representing a database identifier to be used in a query - */ - public function identifier($identifier) { - $obj = new stdClass(); - $obj->type = 'identifier'; - $obj->value = $identifier; - return $obj; - } - -/** - * Returns an object to represent a database expression in a query. Expression objects - * are not sanitized or escaped. - * - * @param string $expression An arbitrary SQL expression to be inserted into a query. - * @return stdClass An object representing a database expression to be used in a query - */ - public function expression($expression) { - $obj = new stdClass(); - $obj->type = 'expression'; - $obj->value = $expression; - return $obj; - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @param array $params Additional options for the query. - * @return boolean - */ - public function rawQuery($sql, $params = array()) { - $this->took = $this->numRows = false; - return $this->execute($sql, $params); - } - -/** - * Queries the database with given SQL statement, and obtains some metadata about the result - * (rows affected, timing, any errors, number of rows in resultset). The query is also logged. - * If Configure::read('debug') is set, the log is shown all the time, else it is only shown on errors. - * - * ### Options - * - * - log - Whether or not the query should be logged to the memory log. - * - * @param string $sql SQL statement - * @param array $options - * @param array $params values to be bound to the query - * @return mixed Resource or object representing the result set, or false on failure - */ - public function execute($sql, $options = array(), $params = array()) { - $options += array('log' => $this->fullDebug); - - $t = microtime(true); - $this->_result = $this->_execute($sql, $params); - - if ($options['log']) { - $this->took = round((microtime(true) - $t) * 1000, 0); - $this->numRows = $this->affected = $this->lastAffected(); - $this->logQuery($sql, $params); - } - - return $this->_result; - } - -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @param array $params list of params to be bound to query - * @param array $prepareOptions Options to be used in the prepare statement - * @return mixed PDOStatement if query executes with no problem, true as the result of a successful, false on error - * query returning no rows, such as a CREATE statement, false otherwise - * @throws PDOException - */ - protected function _execute($sql, $params = array(), $prepareOptions = array()) { - $sql = trim($sql); - if (preg_match('/^(?:CREATE|ALTER|DROP)\s+(?:TABLE|INDEX)/i', $sql)) { - $statements = array_filter(explode(';', $sql)); - if (count($statements) > 1) { - $result = array_map(array($this, '_execute'), $statements); - return array_search(false, $result) === false; - } - } - - try { - $query = $this->_connection->prepare($sql, $prepareOptions); - $query->setFetchMode(PDO::FETCH_LAZY); - if (!$query->execute($params)) { - $this->_results = $query; - $query->closeCursor(); - return false; - } - if (!$query->columnCount()) { - $query->closeCursor(); - if (!$query->rowCount()) { - return true; - } - } - return $query; - } catch (PDOException $e) { - if (isset($query->queryString)) { - $e->queryString = $query->queryString; + if (!isset($linkedModels[$type . '/' . $assoc])) { + if ($model->useDbConfig === $linkModel->useDbConfig) { + $db = $this; } else { - $e->queryString = $sql; + $db = ConnectionManager::getDataSource($linkModel->useDbConfig); } - throw $e; + } elseif ($model->recursive > 1 && ($type === 'belongsTo' || $type === 'hasOne')) { + $db = $this; + } + + if (isset($db) && method_exists($db, 'queryAssociation')) { + $stack = array($assoc); + $stack['_joined'] = $joined; + $db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack); + unset($db); + + if ($type === 'hasMany' || $type === 'hasAndBelongsToMany') { + $filtered[] = $assoc; + } + } } + } + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + $this->_filterResults($resultSet, $model, $filtered); + } } -/** - * Returns a formatted error message from previous database operation. - * - * @param PDOStatement $query the query to extract the error from if any - * @return string Error message with error number - */ - public function lastError(PDOStatement $query = null) { - if ($query) { - $error = $query->errorInfo(); + if (!is_null($recursive)) { + $model->recursive = $_recursive; + } + return $resultSet; + } + + /** + * Passes association results thru afterFind filters of corresponding model + * + * @param array $results Reference of resultset to be filtered + * @param Model $model Instance of model to operate against + * @param array $filtered List of classes already filtered, to be skipped + * @return array Array of results that have been filtered through $model->afterFind + */ + protected function _filterResults(&$results, Model $model, $filtered = array()) { + if (!is_array($results)) { + return array(); + } + $current = reset($results); + if (!is_array($current)) { + return array(); + } + $keys = array_diff(array_keys($current), $filtered, array($model->alias)); + $filtering = array(); + foreach ($keys as $className) { + if (!isset($model->{$className}) || !is_object($model->{$className})) { + continue; + } + $linkedModel = $model->{$className}; + $filtering[] = $className; + foreach ($results as $key => &$result) { + $data = $linkedModel->afterFind(array(array($className => $result[$className])), false); + if (isset($data[0][$className])) { + $result[$className] = $data[0][$className]; } else { - $error = $this->_connection->errorInfo(); + unset($results[$key]); } - if (empty($error[2])) { - return null; - } - return $error[1] . ': ' . $error[2]; + } + } + return $filtering; + } + + /** + * Queries associations. Used to fetch results on recursive models. + * + * @param Model $model Primary Model object + * @param Model $linkModel Linked model that + * @param string $type Association type, one of the model association types ie. hasMany + * @param string $association + * @param array $assocData + * @param array $queryData + * @param boolean $external Whether or not the association query is on an external datasource. + * @param array $resultSet Existing results + * @param integer $recursive Number of levels of association + * @param array $stack + * @return mixed + * @throws CakeException when results cannot be created. + */ + public function queryAssociation(Model $model, &$linkModel, $type, $association, $assocData, &$queryData, $external, &$resultSet, $recursive, $stack) { + if (isset($stack['_joined'])) { + $joined = $stack['_joined']; + unset($stack['_joined']); } -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, - * this returns false. - * - * @param mixed $source - * @return integer Number of affected rows - */ - public function lastAffected($source = null) { - if ($this->hasResult()) { - return $this->_result->rowCount(); + if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) { + if (!is_array($resultSet)) { + throw new CakeException(__d('cake_dev', 'Error in Model %s', get_class($model))); + } + if ($type === 'hasMany' && empty($assocData['limit']) && !empty($assocData['foreignKey'])) { + $ins = $fetch = array(); + foreach ($resultSet as &$result) { + if ($in = $this->insertQueryData('{$__cakeID__$}', $result, $association, $assocData, $model, $linkModel, $stack)) { + $ins[] = $in; + } } - return 0; - } -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @param mixed $source Not used - * @return integer Number of rows in resultset - */ - public function lastNumRows($source = null) { - return $this->lastAffected(); - } + if (!empty($ins)) { + $ins = array_unique($ins); + $fetch = $this->fetchAssociated($model, $query, $ins); + } -/** - * DataSource Query abstraction - * - * @return resource Result resource identifier. - */ - public function query() { - $args = func_get_args(); - $fields = null; - $order = null; - $limit = null; - $page = null; - $recursive = null; + if (!empty($fetch) && is_array($fetch)) { + if ($recursive > 0) { + foreach ($linkModel->associations() as $type1) { + foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { + $deepModel = $linkModel->{$assoc1}; + $tmpStack = $stack; + $tmpStack[] = $assoc1; - if (count($args) === 1) { - return $this->fetchAll($args[0]); - } elseif (count($args) > 1 && (strpos($args[0], 'findBy') === 0 || strpos($args[0], 'findAllBy') === 0)) { - $params = $args[1]; - - if (substr($args[0], 0, 6) === 'findBy') { - $all = false; - $field = Inflector::underscore(substr($args[0], 6)); - } else { - $all = true; - $field = Inflector::underscore(substr($args[0], 9)); - } - - $or = (strpos($field, '_or_') !== false); - if ($or) { - $field = explode('_or_', $field); - } else { - $field = explode('_and_', $field); - } - $off = count($field) - 1; - - if (isset($params[1 + $off])) { - $fields = $params[1 + $off]; - } - - if (isset($params[2 + $off])) { - $order = $params[2 + $off]; - } - - if (!array_key_exists(0, $params)) { - return false; - } - - $c = 0; - $conditions = array(); - - foreach ($field as $f) { - $conditions[$args[2]->alias . '.' . $f] = $params[$c++]; - } - - if ($or) { - $conditions = array('OR' => $conditions); - } - - if ($all) { - if (isset($params[3 + $off])) { - $limit = $params[3 + $off]; + if ($linkModel->useDbConfig === $deepModel->useDbConfig) { + $db = $this; + } else { + $db = ConnectionManager::getDataSource($deepModel->useDbConfig); } - - if (isset($params[4 + $off])) { - $page = $params[4 + $off]; - } - - if (isset($params[5 + $off])) { - $recursive = $params[5 + $off]; - } - return $args[2]->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive')); + $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); + } } - if (isset($params[3 + $off])) { - $recursive = $params[3 + $off]; - } - return $args[2]->find('first', compact('conditions', 'fields', 'order', 'recursive')); + } } - if (isset($args[1]) && $args[1] === true) { - return $this->fetchAll($args[0], true); - } elseif (isset($args[1]) && !is_array($args[1])) { - return $this->fetchAll($args[0], false); - } elseif (isset($args[1]) && is_array($args[1])) { - if (isset($args[2])) { - $cache = $args[2]; - } else { - $cache = true; - } - return $this->fetchAll($args[0], $args[1], array('cache' => $cache)); + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + $this->_filterResults($fetch, $model); } - } - -/** - * Returns a row from current resultset as an array - * - * @param string $sql Some SQL to be executed. - * @return array The fetched row as an array - */ - public function fetchRow($sql = null) { - if (is_string($sql) && strlen($sql) > 5 && !$this->execute($sql)) { - return null; + return $this->_mergeHasMany($resultSet, $fetch, $association, $model, $linkModel); + } elseif ($type === 'hasAndBelongsToMany') { + $ins = $fetch = array(); + foreach ($resultSet as &$result) { + if ($in = $this->insertQueryData('{$__cakeID__$}', $result, $association, $assocData, $model, $linkModel, $stack)) { + $ins[] = $in; + } + } + if (!empty($ins)) { + $ins = array_unique($ins); + if (count($ins) > 1) { + $query = str_replace('{$__cakeID__$}', '(' . implode(', ', $ins) . ')', $query); + $query = str_replace('= (', 'IN (', $query); + } else { + $query = str_replace('{$__cakeID__$}', $ins[0], $query); + } + $query = str_replace(' WHERE 1 = 1', '', $query); } - if ($this->hasResult()) { - $this->resultSet($this->_result); - $resultRow = $this->fetchResult(); - if (isset($resultRow[0])) { - $this->fetchVirtualField($resultRow); - } - return $resultRow; - } - return null; - } + $foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey']; + $joinKeys = array($foreignKey, $model->hasAndBelongsToMany[$association]['associationForeignKey']); + list($with, $habtmFields) = $model->joinModel($model->hasAndBelongsToMany[$association]['with'], $joinKeys); + $habtmFieldsCount = count($habtmFields); + $q = $this->insertQueryData($query, null, $association, $assocData, $model, $linkModel, $stack); -/** - * Returns an array of all result rows for a given SQL query. - * Returns false if no rows matched. - * - * ### Options - * - * - `cache` - Returns the cached version of the query, if exists and stores the result in cache. - * This is a non-persistent cache, and only lasts for a single request. This option - * defaults to true. If you are directly calling this method, you can disable caching - * by setting $options to `false` - * - * @param string $sql SQL statement - * @param array $params parameters to be bound as values for the SQL statement - * @param array $options additional options for the query. - * @return boolean|array Array of resultset rows, or false if no rows matched - */ - public function fetchAll($sql, $params = array(), $options = array()) { - if (is_string($options)) { - $options = array('modelName' => $options); - } - if (is_bool($params)) { - $options['cache'] = $params; - $params = array(); - } - $options += array('cache' => true); - $cache = $options['cache']; - if ($cache && ($cached = $this->getQueryCache($sql, $params)) !== false) { - return $cached; - } - if ($result = $this->execute($sql, array(), $params)) { - $out = array(); - - if ($this->hasResult()) { - $first = $this->fetchRow(); - if ($first) { - $out[] = $first; - } - while ($item = $this->fetchResult()) { - if (isset($item[0])) { - $this->fetchVirtualField($item); - } - $out[] = $item; - } - } - - if (!is_bool($result) && $cache) { - $this->_writeQueryCache($sql, $out, $params); - } - - if (empty($out) && is_bool($this->_result)) { - return $this->_result; - } - return $out; - } - return false; - } - -/** - * Fetches the next row from the current result set - * - * @return boolean - */ - public function fetchResult() { - return false; - } - -/** - * Modifies $result array to place virtual fields in model entry where they belongs to - * - * @param array $result Reference to the fetched row - * @return void - */ - public function fetchVirtualField(&$result) { - if (isset($result[0]) && is_array($result[0])) { - foreach ($result[0] as $field => $value) { - if (strpos($field, $this->virtualFieldSeparator) === false) { - continue; - } - list($alias, $virtual) = explode($this->virtualFieldSeparator, $field); - - if (!ClassRegistry::isKeySet($alias)) { - return; - } - $model = ClassRegistry::getObject($alias); - if ($model->isVirtualField($virtual)) { - $result[$alias][$virtual] = $value; - unset($result[0][$field]); - } - } - if (empty($result[0])) { - unset($result[0]); - } - } - } - -/** - * Returns a single field of the first of query results for a given SQL query, or false if empty. - * - * @param string $name Name of the field - * @param string $sql SQL query - * @return mixed Value of field read. - */ - public function field($name, $sql) { - $data = $this->fetchRow($sql); - if (empty($data[$name])) { - return false; - } - return $data[$name]; - } - -/** - * Empties the method caches. - * These caches are used by DboSource::name() and DboSource::conditions() - * - * @return void - */ - public function flushMethodCache() { - $this->_methodCacheChange = true; - self::$methodCache = array(); - } - -/** - * Cache a value into the methodCaches. Will respect the value of DboSource::$cacheMethods. - * Will retrieve a value from the cache if $value is null. - * - * If caching is disabled and a write is attempted, the $value will be returned. - * A read will either return the value or null. - * - * @param string $method Name of the method being cached. - * @param string $key The key name for the cache operation. - * @param mixed $value The value to cache into memory. - * @return mixed Either null on failure, or the value if its set. - */ - public function cacheMethod($method, $key, $value = null) { - if ($this->cacheMethods === false) { - return $value; - } - if (empty(self::$methodCache)) { - self::$methodCache = Cache::read('method_cache', '_cake_core_'); - } - if ($value === null) { - return (isset(self::$methodCache[$method][$key])) ? self::$methodCache[$method][$key] : null; - } - $this->_methodCacheChange = true; - return self::$methodCache[$method][$key] = $value; - } - -/** - * Returns a quoted name of $data for use in an SQL statement. - * Strips fields out of SQL functions before quoting. - * - * Results of this method are stored in a memory cache. This improves performance, but - * because the method uses a hashing algorithm it can have collisions. - * Setting DboSource::$cacheMethods to false will disable the memory cache. - * - * @param mixed $data Either a string with a column to quote. An array of columns to quote or an - * object from DboSource::expression() or DboSource::identifier() - * @return string SQL field - */ - public function name($data) { - if (is_object($data) && isset($data->type)) { - return $data->value; - } - if ($data === '*') { - return '*'; - } - if (is_array($data)) { - foreach ($data as $i => $dataItem) { - $data[$i] = $this->name($dataItem); - } - return $data; - } - $cacheKey = md5($this->startQuote . $data . $this->endQuote); - if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) { - return $return; - } - $data = trim($data); - if (preg_match('/^[\w-]+(?:\.[^ \*]*)*$/', $data)) { // string, string.string - if (strpos($data, '.') === false) { // string - return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote); - } - $items = explode('.', $data); - return $this->cacheMethod(__FUNCTION__, $cacheKey, - $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote - ); - } - if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.* - return $this->cacheMethod(__FUNCTION__, $cacheKey, - $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data) - ); - } - if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions - return $this->cacheMethod(__FUNCTION__, $cacheKey, - $matches[1] . '(' . $this->name($matches[2]) . ')' - ); - } - if ( - preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/i', $data, $matches - )) { - return $this->cacheMethod( - __FUNCTION__, $cacheKey, - preg_replace( - '/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]) - ) - ); - } - if (preg_match('/^[\w-_\s]*[\w-_]+/', $data)) { - return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote); - } - return $this->cacheMethod(__FUNCTION__, $cacheKey, $data); - } - -/** - * Checks if the source is connected to the database. - * - * @return boolean True if the database is connected, else false - */ - public function isConnected() { - return $this->connected; - } - -/** - * Checks if the result is valid - * - * @return boolean True if the result is valid else false - */ - public function hasResult() { - return is_a($this->_result, 'PDOStatement'); - } - -/** - * Get the query log as an array. - * - * @param boolean $sorted Get the queries sorted by time taken, defaults to false. - * @param boolean $clear If True the existing log will cleared. - * @return array Array of queries run as an array - */ - public function getLog($sorted = false, $clear = true) { - if ($sorted) { - $log = sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC); + if ($q !== false) { + $fetch = $this->fetchAll($q, $model->cacheQueries); } else { - $log = $this->_queriesLog; + $fetch = null; } - if ($clear) { - $this->_queriesLog = array(); + if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { + $this->_filterResults($fetch, $model); } - return array('log' => $log, 'count' => $this->_queriesCnt, 'time' => $this->_queriesTime); - } + } -/** - * Outputs the contents of the queries log. If in a non-CLI environment the sql_log element - * will be rendered and output. If in a CLI environment, a plain text log is generated. - * - * @param boolean $sorted Get the queries sorted by time taken, defaults to false. - * @return void - */ - public function showLog($sorted = false) { - $log = $this->getLog($sorted, false); - if (empty($log['log'])) { - return; - } - if (PHP_SAPI !== 'cli') { - $controller = null; - $View = new View($controller, false); - $View->set('logs', array($this->configKeyName => $log)); - echo $View->element('sql_dump', array('_forced_from_dbo_' => true)); - } else { - foreach ($log['log'] as $k => $i) { - print (($k + 1) . ". {$i['query']}\n"); + $modelAlias = $model->alias; + $modelPK = $model->primaryKey; + foreach ($resultSet as &$row) { + if ($type !== 'hasAndBelongsToMany') { + $q = $this->insertQueryData($query, $row, $association, $assocData, $model, $linkModel, $stack); + $fetch = null; + if ($q !== false) { + $joinedData = array(); + if (($type === 'belongsTo' || $type === 'hasOne') && isset($row[$linkModel->alias], $joined[$model->alias]) && in_array($linkModel->alias, $joined[$model->alias])) { + $joinedData = Hash::filter($row[$linkModel->alias]); + if (!empty($joinedData)) { + $fetch[0] = array($linkModel->alias => $row[$linkModel->alias]); + } + } else { + $fetch = $this->fetchAll($q, $model->cacheQueries); } + } } + $selfJoin = $linkModel->name === $model->name; + + if (!empty($fetch) && is_array($fetch)) { + if ($recursive > 0) { + foreach ($linkModel->associations() as $type1) { + foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { + $deepModel = $linkModel->{$assoc1}; + + if ($type1 === 'belongsTo' || ($deepModel->alias === $modelAlias && $type === 'belongsTo') || ($deepModel->alias !== $modelAlias)) { + $tmpStack = $stack; + $tmpStack[] = $assoc1; + if ($linkModel->useDbConfig == $deepModel->useDbConfig) { + $db = $this; + } else { + $db = ConnectionManager::getDataSource($deepModel->useDbConfig); + } + $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); + } + } + } + } + if ($type === 'hasAndBelongsToMany') { + $merge = array(); + + foreach ($fetch as $data) { + if (isset($data[$with]) && $data[$with][$foreignKey] === $row[$modelAlias][$modelPK]) { + if ($habtmFieldsCount <= 2) { + unset($data[$with]); + } + $merge[] = $data; + } + } + if (empty($merge) && !isset($row[$association])) { + $row[$association] = $merge; + } else { + $this->_mergeAssociation($row, $merge, $association, $type); + } + } else { + $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin); + } + if (isset($row[$association]) && $type !== 'hasAndBelongsToMany') { + $row[$association] = $linkModel->afterFind($row[$association], false); + } + } else { + $tempArray[0][$association] = false; + $this->_mergeAssociation($row, $tempArray, $association, $type, $selfJoin); + } + } + } + } + + /** + * A more efficient way to fetch associations. + * + * @param Model $model Primary model object + * @param string $query Association query + * @param array $ids Array of IDs of associated records + * @return array Association results + */ + public function fetchAssociated(Model $model, $query, $ids) { + $query = str_replace('{$__cakeID__$}', implode(', ', $ids), $query); + if (count($ids) > 1) { + $query = str_replace('= (', 'IN (', $query); + } + return $this->fetchAll($query, $model->cacheQueries); + } + + /** + * Merge the results of hasMany relations. + * + * @param array $resultSet Data to merge into + * @param array $merge Data to merge + * @param string $association Name of Model being Merged + * @param Model $model Model being merged onto + * @param Model $linkModel Model being merged + * @return void + */ + protected function _mergeHasMany(&$resultSet, $merge, $association, $model, $linkModel) { + $modelAlias = $model->alias; + $modelPK = $model->primaryKey; + $modelFK = $model->hasMany[$association]['foreignKey']; + foreach ($resultSet as &$result) { + if (!isset($result[$modelAlias])) { + continue; + } + $merged = array(); + foreach ($merge as $data) { + if ($result[$modelAlias][$modelPK] === $data[$association][$modelFK]) { + if (count($data) > 1) { + $data = array_merge($data[$association], $data); + unset($data[$association]); + foreach ($data as $key => $name) { + if (is_numeric($key)) { + $data[$association][] = $name; + unset($data[$key]); + } + } + $merged[] = $data; + } else { + $merged[] = $data[$association]; + } + } + } + $result = Hash::mergeDiff($result, array($association => $merged)); + } + } + + /** + * Merge association of merge into data + * + * @param array $data + * @param array $merge + * @param string $association + * @param string $type + * @param boolean $selfJoin + * @return void + */ + protected function _mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) { + if (isset($merge[0]) && !isset($merge[0][$association])) { + $association = Inflector::pluralize($association); } -/** - * Log given SQL query. - * - * @param string $sql SQL statement - * @param array $params Values binded to the query (prepared statements) - * @return void - */ - public function logQuery($sql, $params = array()) { - $this->_queriesCnt++; - $this->_queriesTime += $this->took; - $this->_queriesLog[] = array( - 'query' => $sql, - 'params' => $params, - 'affected' => $this->affected, - 'numRows' => $this->numRows, - 'took' => $this->took + if ($type === 'belongsTo' || $type === 'hasOne') { + if (isset($merge[$association])) { + $data[$association] = $merge[$association][0]; + } else { + if (count($merge[0][$association]) > 1) { + foreach ($merge[0] as $assoc => $data2) { + if ($assoc !== $association) { + $merge[0][$association][$assoc] = $data2; + } + } + } + if (!isset($data[$association])) { + $data[$association] = array(); + if ($merge[0][$association]) { + $data[$association] = $merge[0][$association]; + } + } else { + if (is_array($merge[0][$association])) { + foreach ($data[$association] as $k => $v) { + if (!is_array($v)) { + $dataAssocTmp[$k] = $v; + } + } + + foreach ($merge[0][$association] as $k => $v) { + if (!is_array($v)) { + $mergeAssocTmp[$k] = $v; + } + } + $dataKeys = array_keys($data); + $mergeKeys = array_keys($merge[0]); + + if ($mergeKeys[0] === $dataKeys[0] || $mergeKeys === $dataKeys) { + $data[$association][$association] = $merge[0][$association]; + } else { + $diff = Hash::diff($dataAssocTmp, $mergeAssocTmp); + $data[$association] = array_merge($merge[0][$association], $diff); + } + } elseif ($selfJoin && array_key_exists($association, $merge[0])) { + $data[$association] = array_merge($data[$association], array($association => array())); + } + } + } + } else { + if (isset($merge[0][$association]) && $merge[0][$association] === false) { + if (!isset($data[$association])) { + $data[$association] = array(); + } + } else { + foreach ($merge as $row) { + $insert = array(); + if (count($row) === 1) { + $insert = $row[$association]; + } elseif (isset($row[$association])) { + $insert = array_merge($row[$association], $row); + unset($insert[$association]); + } + + if (empty($data[$association]) || (isset($data[$association]) && !in_array($insert, $data[$association], true))) { + $data[$association][] = $insert; + } + } + } + } + } + + /** + * Generates an array representing a query or part of a query from a single model or two associated models + * + * @param Model $model + * @param Model $linkModel + * @param string $type + * @param string $association + * @param array $assocData + * @param array $queryData + * @param boolean $external + * @param array $resultSet + * @return mixed + */ + public function generateAssociationQuery(Model $model, $linkModel, $type, $association, $assocData, &$queryData, $external, &$resultSet) { + $queryData = $this->_scrubQueryData($queryData); + $assocData = $this->_scrubQueryData($assocData); + $modelAlias = $model->alias; + + if (empty($queryData['fields'])) { + $queryData['fields'] = $this->fields($model, $modelAlias); + } elseif (!empty($model->hasMany) && $model->recursive > -1) { + $assocFields = $this->fields($model, $modelAlias, array("{$modelAlias}.{$model->primaryKey}")); + $passedFields = $queryData['fields']; + if (count($passedFields) === 1) { + if (strpos($passedFields[0], $assocFields[0]) === false && !preg_match('/^[a-z]+\(/i', $passedFields[0])) { + $queryData['fields'] = array_merge($passedFields, $assocFields); + } else { + $queryData['fields'] = $passedFields; + } + } else { + $queryData['fields'] = array_merge($passedFields, $assocFields); + } + unset($assocFields, $passedFields); + } + + if ($linkModel === null) { + return $this->buildStatement( + array( + 'fields' => array_unique($queryData['fields']), + 'table' => $this->fullTableName($model), + 'alias' => $modelAlias, + 'limit' => $queryData['limit'], + 'offset' => $queryData['offset'], + 'joins' => $queryData['joins'], + 'conditions' => $queryData['conditions'], + 'order' => $queryData['order'], + 'group' => $queryData['group'] + ), $model + ); + } + if ($external && !empty($assocData['finderQuery'])) { + return $assocData['finderQuery']; + } + + $self = $model->name === $linkModel->name; + $fields = array(); + + if ($external || (in_array($type, array('hasOne', 'belongsTo')) && $assocData['fields'] !== false)) { + $fields = $this->fields($linkModel, $association, $assocData['fields']); + } + if (empty($assocData['offset']) && !empty($assocData['page'])) { + $assocData['offset'] = ($assocData['page'] - 1) * $assocData['limit']; + } + + switch ($type) { + case 'hasOne': + case 'belongsTo': + $conditions = $this->_mergeConditions( + $assocData['conditions'], $this->getConstraint($type, $model, $linkModel, $association, array_merge($assocData, compact('external', 'self'))) ); - if (count($this->_queriesLog) > $this->_queriesLogMax) { - array_shift($this->_queriesLog); - } - } -/** - * Gets full table name including prefix - * - * @param Model|string $model Either a Model object or a string table name. - * @param boolean $quote Whether you want the table name quoted. - * @param boolean $schema Whether you want the schema name included. - * @return string Full quoted table name - */ - public function fullTableName($model, $quote = true, $schema = true) { - if (is_object($model)) { - $schemaName = $model->schemaName; - $table = $model->tablePrefix . $model->table; - } elseif (!empty($this->config['prefix']) && strpos($model, $this->config['prefix']) !== 0) { - $table = $this->config['prefix'] . strval($model); + if (!$self && $external) { + foreach ($conditions as $key => $condition) { + if (is_numeric($key) && strpos($condition, $modelAlias . '.') !== false) { + unset($conditions[$key]); + } + } + } + + if ($external) { + $query = array_merge($assocData, array( + 'conditions' => $conditions, + 'table' => $this->fullTableName($linkModel), + 'fields' => $fields, + 'alias' => $association, + 'group' => null + )); } else { - $table = strval($model); - } - if ($schema && !isset($schemaName)) { - $schemaName = $this->getSchemaName(); - } + $join = array( + 'table' => $linkModel, + 'alias' => $association, + 'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT', + 'conditions' => trim($this->conditions($conditions, true, false, $model)) + ); + $queryData['fields'] = array_merge($queryData['fields'], $fields); - if ($quote) { - if ($schema && !empty($schemaName)) { - if (false == strstr($table, '.')) { - return $this->name($schemaName) . '.' . $this->name($table); - } - } - return $this->name($table); + if (!empty($assocData['order'])) { + $queryData['order'][] = $assocData['order']; + } + if (!in_array($join, $queryData['joins'])) { + $queryData['joins'][] = $join; + } + return true; } - if ($schema && !empty($schemaName)) { - if (false == strstr($table, '.')) { - return $schemaName . '.' . $table; - } - } - return $table; - } - -/** - * The "C" in CRUD - * - * Creates new records in the database. - * - * @param Model $model Model object that the record is for. - * @param array $fields An array of field names to insert. If null, $model->data will be - * used to generate field names. - * @param array $values An array of values with keys matching the fields. If null, $model->data will - * be used to generate values. - * @return boolean Success - */ - public function create(Model $model, $fields = null, $values = null) { - $id = null; - - if (!$fields) { - unset($fields, $values); - $fields = array_keys($model->data); - $values = array_values($model->data); - } - $count = count($fields); - - for ($i = 0; $i < $count; $i++) { - $valueInsert[] = $this->value($values[$i], $model->getColumnType($fields[$i])); - $fieldInsert[] = $this->name($fields[$i]); - if ($fields[$i] == $model->primaryKey) { - $id = $values[$i]; - } + break; + case 'hasMany': + $assocData['fields'] = $this->fields($linkModel, $association, $assocData['fields']); + if (!empty($assocData['foreignKey'])) { + $assocData['fields'] = array_merge($assocData['fields'], $this->fields($linkModel, $association, array("{$association}.{$assocData['foreignKey']}"))); } $query = array( - 'table' => $this->fullTableName($model), - 'fields' => implode(', ', $fieldInsert), - 'values' => implode(', ', $valueInsert) + 'conditions' => $this->_mergeConditions($this->getConstraint('hasMany', $model, $linkModel, $association, $assocData), $assocData['conditions']), + 'fields' => array_unique($assocData['fields']), + 'table' => $this->fullTableName($linkModel), + 'alias' => $association, + 'order' => $assocData['order'], + 'limit' => $assocData['limit'], + 'offset' => $assocData['offset'], + 'group' => null ); + break; + case 'hasAndBelongsToMany': + $joinFields = array(); + $joinAssoc = null; - if ($this->execute($this->renderStatement('create', $query))) { - if (empty($id)) { - $id = $this->lastInsertId($this->fullTableName($model, false, false), $model->primaryKey); - } - $model->setInsertID($id); - $model->id = $id; - return true; - } - $model->onError(); - return false; - } + if (isset($assocData['with']) && !empty($assocData['with'])) { + $joinKeys = array($assocData['foreignKey'], $assocData['associationForeignKey']); + list($with, $joinFields) = $model->joinModel($assocData['with'], $joinKeys); -/** - * The "R" in CRUD - * - * Reads record(s) from the database. - * - * @param Model $model A Model object that the query is for. - * @param array $queryData An array of queryData information containing keys similar to Model::find() - * @param integer $recursive Number of levels of association - * @return mixed boolean false on error/failure. An array of results on success. - */ - public function read(Model $model, $queryData = array(), $recursive = null) { - $queryData = $this->_scrubQueryData($queryData); + $joinTbl = $model->{$with}; + $joinAlias = $joinTbl; - $null = null; - $array = array('callbacks' => $queryData['callbacks']); - $linkedModels = array(); - $bypass = false; - - if ($recursive === null && isset($queryData['recursive'])) { - $recursive = $queryData['recursive']; - } - - if (!is_null($recursive)) { - $_recursive = $model->recursive; - $model->recursive = $recursive; - } - - if (!empty($queryData['fields'])) { - $bypass = true; - $queryData['fields'] = $this->fields($model, null, $queryData['fields']); + if (is_array($joinFields) && !empty($joinFields)) { + $joinAssoc = $joinAlias = $model->{$with}->alias; + $joinFields = $this->fields($model->{$with}, $joinAlias, $joinFields); + } else { + $joinFields = array(); + } } else { - $queryData['fields'] = $this->fields($model); + $joinTbl = $assocData['joinTable']; + $joinAlias = $this->fullTableName($assocData['joinTable']); } + $query = array( + 'conditions' => $assocData['conditions'], + 'limit' => $assocData['limit'], + 'offset' => $assocData['offset'], + 'table' => $this->fullTableName($linkModel), + 'alias' => $association, + 'fields' => array_merge($this->fields($linkModel, $association, $assocData['fields']), $joinFields), + 'order' => $assocData['order'], + 'group' => null, + 'joins' => array(array( + 'table' => $joinTbl, + 'alias' => $joinAssoc, + 'conditions' => $this->getConstraint('hasAndBelongsToMany', $model, $linkModel, $joinAlias, $assocData, $association) + )) + ); + break; + } + if (isset($query)) { + return $this->buildStatement($query, $model); + } + return null; + } - $_associations = $model->associations(); + /** + * Returns a conditions array for the constraint between two models + * + * @param string $type Association type + * @param Model $model Model object + * @param string $linkModel + * @param string $alias + * @param array $assoc + * @param string $alias2 + * @return array Conditions array defining the constraint between $model and $association + */ + public function getConstraint($type, $model, $linkModel, $alias, $assoc, $alias2 = null) { + $assoc += array('external' => false, 'self' => false); - if ($model->recursive == -1) { - $_associations = array(); - } elseif ($model->recursive === 0) { - unset($_associations[2], $_associations[3]); - } - - foreach ($_associations as $type) { - foreach ($model->{$type} as $assoc => $assocData) { - $linkModel = $model->{$assoc}; - $external = isset($assocData['external']); - - $linkModel->getDataSource(); - if ($model->useDbConfig === $linkModel->useDbConfig) { - if ($bypass) { - $assocData['fields'] = false; - } - if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) { - $linkedModels[$type . '/' . $assoc] = true; - } - } - } - } - - $query = trim($this->generateAssociationQuery($model, null, null, null, null, $queryData, false, $null)); - - $resultSet = $this->fetchAll($query, $model->cacheQueries); - - if ($resultSet === false) { - $model->onError(); - return false; - } - - $filtered = array(); - - if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { - $filtered = $this->_filterResults($resultSet, $model); - } - - if ($model->recursive > -1) { - $joined = array(); - if (isset($queryData['joins'][0]['alias'])) { - $joined[$model->alias] = (array)Hash::extract($queryData['joins'], '{n}.alias'); - } - foreach ($_associations as $type) { - foreach ($model->{$type} as $assoc => $assocData) { - $linkModel = $model->{$assoc}; - - if (!isset($linkedModels[$type . '/' . $assoc])) { - if ($model->useDbConfig === $linkModel->useDbConfig) { - $db = $this; - } else { - $db = ConnectionManager::getDataSource($linkModel->useDbConfig); - } - } elseif ($model->recursive > 1 && ($type === 'belongsTo' || $type === 'hasOne')) { - $db = $this; - } - - if (isset($db) && method_exists($db, 'queryAssociation')) { - $stack = array($assoc); - $stack['_joined'] = $joined; - $db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack); - unset($db); - - if ($type === 'hasMany' || $type === 'hasAndBelongsToMany') { - $filtered[] = $assoc; - } - } - } - } - if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { - $this->_filterResults($resultSet, $model, $filtered); - } - } - - if (!is_null($recursive)) { - $model->recursive = $_recursive; - } - return $resultSet; + if (empty($assoc['foreignKey'])) { + return array(); } -/** - * Passes association results thru afterFind filters of corresponding model - * - * @param array $results Reference of resultset to be filtered - * @param Model $model Instance of model to operate against - * @param array $filtered List of classes already filtered, to be skipped - * @return array Array of results that have been filtered through $model->afterFind - */ - protected function _filterResults(&$results, Model $model, $filtered = array()) { - if (!is_array($results)) { - return array(); - } - $current = reset($results); - if (!is_array($current)) { - return array(); - } - $keys = array_diff(array_keys($current), $filtered, array($model->alias)); - $filtering = array(); - foreach ($keys as $className) { - if (!isset($model->{$className}) || !is_object($model->{$className})) { - continue; - } - $linkedModel = $model->{$className}; - $filtering[] = $className; - foreach ($results as $key => &$result) { - $data = $linkedModel->afterFind(array(array($className => $result[$className])), false); - if (isset($data[0][$className])) { - $result[$className] = $data[0][$className]; - } else { - unset($results[$key]); - } - } - } - return $filtering; + switch (true) { + case ($assoc['external'] && $type === 'hasOne'): + return array("{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'); + case ($assoc['external'] && $type === 'belongsTo'): + return array("{$alias}.{$linkModel->primaryKey}" => '{$__cakeForeignKey__$}'); + case (!$assoc['external'] && $type === 'hasOne'): + return array("{$alias}.{$assoc['foreignKey']}" => $this->identifier("{$model->alias}.{$model->primaryKey}")); + case (!$assoc['external'] && $type === 'belongsTo'): + return array("{$model->alias}.{$assoc['foreignKey']}" => $this->identifier("{$alias}.{$linkModel->primaryKey}")); + case ($type === 'hasMany'): + return array("{$alias}.{$assoc['foreignKey']}" => array('{$__cakeID__$}')); + case ($type === 'hasAndBelongsToMany'): + return array( + array("{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'), + array("{$alias}.{$assoc['associationForeignKey']}" => $this->identifier("{$alias2}.{$linkModel->primaryKey}")) + ); } + return array(); + } -/** - * Queries associations. Used to fetch results on recursive models. - * - * @param Model $model Primary Model object - * @param Model $linkModel Linked model that - * @param string $type Association type, one of the model association types ie. hasMany - * @param string $association - * @param array $assocData - * @param array $queryData - * @param boolean $external Whether or not the association query is on an external datasource. - * @param array $resultSet Existing results - * @param integer $recursive Number of levels of association - * @param array $stack - * @return mixed - * @throws CakeException when results cannot be created. - */ - public function queryAssociation(Model $model, &$linkModel, $type, $association, $assocData, &$queryData, $external, &$resultSet, $recursive, $stack) { - if (isset($stack['_joined'])) { - $joined = $stack['_joined']; - unset($stack['_joined']); - } - - if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) { - if (!is_array($resultSet)) { - throw new CakeException(__d('cake_dev', 'Error in Model %s', get_class($model))); - } - if ($type === 'hasMany' && empty($assocData['limit']) && !empty($assocData['foreignKey'])) { - $ins = $fetch = array(); - foreach ($resultSet as &$result) { - if ($in = $this->insertQueryData('{$__cakeID__$}', $result, $association, $assocData, $model, $linkModel, $stack)) { - $ins[] = $in; - } - } - - if (!empty($ins)) { - $ins = array_unique($ins); - $fetch = $this->fetchAssociated($model, $query, $ins); - } - - if (!empty($fetch) && is_array($fetch)) { - if ($recursive > 0) { - foreach ($linkModel->associations() as $type1) { - foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { - $deepModel = $linkModel->{$assoc1}; - $tmpStack = $stack; - $tmpStack[] = $assoc1; - - if ($linkModel->useDbConfig === $deepModel->useDbConfig) { - $db = $this; - } else { - $db = ConnectionManager::getDataSource($deepModel->useDbConfig); - } - $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); - } - } - } - } - if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { - $this->_filterResults($fetch, $model); - } - return $this->_mergeHasMany($resultSet, $fetch, $association, $model, $linkModel); - } elseif ($type === 'hasAndBelongsToMany') { - $ins = $fetch = array(); - foreach ($resultSet as &$result) { - if ($in = $this->insertQueryData('{$__cakeID__$}', $result, $association, $assocData, $model, $linkModel, $stack)) { - $ins[] = $in; - } - } - if (!empty($ins)) { - $ins = array_unique($ins); - if (count($ins) > 1) { - $query = str_replace('{$__cakeID__$}', '(' . implode(', ', $ins) . ')', $query); - $query = str_replace('= (', 'IN (', $query); - } else { - $query = str_replace('{$__cakeID__$}', $ins[0], $query); - } - $query = str_replace(' WHERE 1 = 1', '', $query); - } - - $foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey']; - $joinKeys = array($foreignKey, $model->hasAndBelongsToMany[$association]['associationForeignKey']); - list($with, $habtmFields) = $model->joinModel($model->hasAndBelongsToMany[$association]['with'], $joinKeys); - $habtmFieldsCount = count($habtmFields); - $q = $this->insertQueryData($query, null, $association, $assocData, $model, $linkModel, $stack); - - if ($q !== false) { - $fetch = $this->fetchAll($q, $model->cacheQueries); - } else { - $fetch = null; - } - if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { - $this->_filterResults($fetch, $model); - } - } - - $modelAlias = $model->alias; - $modelPK = $model->primaryKey; - foreach ($resultSet as &$row) { - if ($type !== 'hasAndBelongsToMany') { - $q = $this->insertQueryData($query, $row, $association, $assocData, $model, $linkModel, $stack); - $fetch = null; - if ($q !== false) { - $joinedData = array(); - if (($type === 'belongsTo' || $type === 'hasOne') && isset($row[$linkModel->alias], $joined[$model->alias]) && in_array($linkModel->alias, $joined[$model->alias])) { - $joinedData = Hash::filter($row[$linkModel->alias]); - if (!empty($joinedData)) { - $fetch[0] = array($linkModel->alias => $row[$linkModel->alias]); - } - } else { - $fetch = $this->fetchAll($q, $model->cacheQueries); - } - } - } - $selfJoin = $linkModel->name === $model->name; - - if (!empty($fetch) && is_array($fetch)) { - if ($recursive > 0) { - foreach ($linkModel->associations() as $type1) { - foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { - $deepModel = $linkModel->{$assoc1}; - - if ($type1 === 'belongsTo' || ($deepModel->alias === $modelAlias && $type === 'belongsTo') || ($deepModel->alias !== $modelAlias)) { - $tmpStack = $stack; - $tmpStack[] = $assoc1; - if ($linkModel->useDbConfig == $deepModel->useDbConfig) { - $db = $this; - } else { - $db = ConnectionManager::getDataSource($deepModel->useDbConfig); - } - $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); - } - } - } - } - if ($type === 'hasAndBelongsToMany') { - $merge = array(); - - foreach ($fetch as $data) { - if (isset($data[$with]) && $data[$with][$foreignKey] === $row[$modelAlias][$modelPK]) { - if ($habtmFieldsCount <= 2) { - unset($data[$with]); - } - $merge[] = $data; - } - } - if (empty($merge) && !isset($row[$association])) { - $row[$association] = $merge; - } else { - $this->_mergeAssociation($row, $merge, $association, $type); - } - } else { - $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin); - } - if (isset($row[$association]) && $type !== 'hasAndBelongsToMany') { - $row[$association] = $linkModel->afterFind($row[$association], false); - } - } else { - $tempArray[0][$association] = false; - $this->_mergeAssociation($row, $tempArray, $association, $type, $selfJoin); - } - } - } - } - -/** - * A more efficient way to fetch associations. - * - * @param Model $model Primary model object - * @param string $query Association query - * @param array $ids Array of IDs of associated records - * @return array Association results - */ - public function fetchAssociated(Model $model, $query, $ids) { - $query = str_replace('{$__cakeID__$}', implode(', ', $ids), $query); - if (count($ids) > 1) { - $query = str_replace('= (', 'IN (', $query); - } - return $this->fetchAll($query, $model->cacheQueries); - } - -/** - * Merge the results of hasMany relations. - * - * @param array $resultSet Data to merge into - * @param array $merge Data to merge - * @param string $association Name of Model being Merged - * @param Model $model Model being merged onto - * @param Model $linkModel Model being merged - * @return void - */ - protected function _mergeHasMany(&$resultSet, $merge, $association, $model, $linkModel) { - $modelAlias = $model->alias; - $modelPK = $model->primaryKey; - $modelFK = $model->hasMany[$association]['foreignKey']; - foreach ($resultSet as &$result) { - if (!isset($result[$modelAlias])) { - continue; - } - $merged = array(); - foreach ($merge as $data) { - if ($result[$modelAlias][$modelPK] === $data[$association][$modelFK]) { - if (count($data) > 1) { - $data = array_merge($data[$association], $data); - unset($data[$association]); - foreach ($data as $key => $name) { - if (is_numeric($key)) { - $data[$association][] = $name; - unset($data[$key]); - } - } - $merged[] = $data; - } else { - $merged[] = $data[$association]; - } - } - } - $result = Hash::mergeDiff($result, array($association => $merged)); - } - } - -/** - * Merge association of merge into data - * - * @param array $data - * @param array $merge - * @param string $association - * @param string $type - * @param boolean $selfJoin - * @return void - */ - protected function _mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) { - if (isset($merge[0]) && !isset($merge[0][$association])) { - $association = Inflector::pluralize($association); - } - - if ($type === 'belongsTo' || $type === 'hasOne') { - if (isset($merge[$association])) { - $data[$association] = $merge[$association][0]; - } else { - if (count($merge[0][$association]) > 1) { - foreach ($merge[0] as $assoc => $data2) { - if ($assoc !== $association) { - $merge[0][$association][$assoc] = $data2; - } - } - } - if (!isset($data[$association])) { - $data[$association] = array(); - if ($merge[0][$association]) { - $data[$association] = $merge[0][$association]; - } - } else { - if (is_array($merge[0][$association])) { - foreach ($data[$association] as $k => $v) { - if (!is_array($v)) { - $dataAssocTmp[$k] = $v; - } - } - - foreach ($merge[0][$association] as $k => $v) { - if (!is_array($v)) { - $mergeAssocTmp[$k] = $v; - } - } - $dataKeys = array_keys($data); - $mergeKeys = array_keys($merge[0]); - - if ($mergeKeys[0] === $dataKeys[0] || $mergeKeys === $dataKeys) { - $data[$association][$association] = $merge[0][$association]; - } else { - $diff = Hash::diff($dataAssocTmp, $mergeAssocTmp); - $data[$association] = array_merge($merge[0][$association], $diff); - } - } elseif ($selfJoin && array_key_exists($association, $merge[0])) { - $data[$association] = array_merge($data[$association], array($association => array())); - } - } - } - } else { - if (isset($merge[0][$association]) && $merge[0][$association] === false) { - if (!isset($data[$association])) { - $data[$association] = array(); - } - } else { - foreach ($merge as $row) { - $insert = array(); - if (count($row) === 1) { - $insert = $row[$association]; - } elseif (isset($row[$association])) { - $insert = array_merge($row[$association], $row); - unset($insert[$association]); - } - - if (empty($data[$association]) || (isset($data[$association]) && !in_array($insert, $data[$association], true))) { - $data[$association][] = $insert; - } - } - } - } - } - -/** - * Generates an array representing a query or part of a query from a single model or two associated models - * - * @param Model $model - * @param Model $linkModel - * @param string $type - * @param string $association - * @param array $assocData - * @param array $queryData - * @param boolean $external - * @param array $resultSet - * @return mixed - */ - public function generateAssociationQuery(Model $model, $linkModel, $type, $association, $assocData, &$queryData, $external, &$resultSet) { - $queryData = $this->_scrubQueryData($queryData); - $assocData = $this->_scrubQueryData($assocData); - $modelAlias = $model->alias; - - if (empty($queryData['fields'])) { - $queryData['fields'] = $this->fields($model, $modelAlias); - } elseif (!empty($model->hasMany) && $model->recursive > -1) { - $assocFields = $this->fields($model, $modelAlias, array("{$modelAlias}.{$model->primaryKey}")); - $passedFields = $queryData['fields']; - if (count($passedFields) === 1) { - if (strpos($passedFields[0], $assocFields[0]) === false && !preg_match('/^[a-z]+\(/i', $passedFields[0])) { - $queryData['fields'] = array_merge($passedFields, $assocFields); - } else { - $queryData['fields'] = $passedFields; - } - } else { - $queryData['fields'] = array_merge($passedFields, $assocFields); - } - unset($assocFields, $passedFields); - } - - if ($linkModel === null) { - return $this->buildStatement( - array( - 'fields' => array_unique($queryData['fields']), - 'table' => $this->fullTableName($model), - 'alias' => $modelAlias, - 'limit' => $queryData['limit'], - 'offset' => $queryData['offset'], - 'joins' => $queryData['joins'], - 'conditions' => $queryData['conditions'], - 'order' => $queryData['order'], - 'group' => $queryData['group'] - ), - $model - ); - } - if ($external && !empty($assocData['finderQuery'])) { - return $assocData['finderQuery']; - } - - $self = $model->name === $linkModel->name; - $fields = array(); - - if ($external || (in_array($type, array('hasOne', 'belongsTo')) && $assocData['fields'] !== false)) { - $fields = $this->fields($linkModel, $association, $assocData['fields']); - } - if (empty($assocData['offset']) && !empty($assocData['page'])) { - $assocData['offset'] = ($assocData['page'] - 1) * $assocData['limit']; - } - - switch ($type) { - case 'hasOne': - case 'belongsTo': - $conditions = $this->_mergeConditions( - $assocData['conditions'], - $this->getConstraint($type, $model, $linkModel, $association, array_merge($assocData, compact('external', 'self'))) - ); - - if (!$self && $external) { - foreach ($conditions as $key => $condition) { - if (is_numeric($key) && strpos($condition, $modelAlias . '.') !== false) { - unset($conditions[$key]); - } - } - } - - if ($external) { - $query = array_merge($assocData, array( - 'conditions' => $conditions, - 'table' => $this->fullTableName($linkModel), - 'fields' => $fields, - 'alias' => $association, - 'group' => null - )); - } else { - $join = array( - 'table' => $linkModel, - 'alias' => $association, - 'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT', - 'conditions' => trim($this->conditions($conditions, true, false, $model)) - ); - $queryData['fields'] = array_merge($queryData['fields'], $fields); - - if (!empty($assocData['order'])) { - $queryData['order'][] = $assocData['order']; - } - if (!in_array($join, $queryData['joins'])) { - $queryData['joins'][] = $join; - } - return true; - } - break; - case 'hasMany': - $assocData['fields'] = $this->fields($linkModel, $association, $assocData['fields']); - if (!empty($assocData['foreignKey'])) { - $assocData['fields'] = array_merge($assocData['fields'], $this->fields($linkModel, $association, array("{$association}.{$assocData['foreignKey']}"))); - } - $query = array( - 'conditions' => $this->_mergeConditions($this->getConstraint('hasMany', $model, $linkModel, $association, $assocData), $assocData['conditions']), - 'fields' => array_unique($assocData['fields']), - 'table' => $this->fullTableName($linkModel), - 'alias' => $association, - 'order' => $assocData['order'], - 'limit' => $assocData['limit'], - 'offset' => $assocData['offset'], - 'group' => null - ); - break; - case 'hasAndBelongsToMany': - $joinFields = array(); - $joinAssoc = null; - - if (isset($assocData['with']) && !empty($assocData['with'])) { - $joinKeys = array($assocData['foreignKey'], $assocData['associationForeignKey']); - list($with, $joinFields) = $model->joinModel($assocData['with'], $joinKeys); - - $joinTbl = $model->{$with}; - $joinAlias = $joinTbl; - - if (is_array($joinFields) && !empty($joinFields)) { - $joinAssoc = $joinAlias = $model->{$with}->alias; - $joinFields = $this->fields($model->{$with}, $joinAlias, $joinFields); - } else { - $joinFields = array(); - } - } else { - $joinTbl = $assocData['joinTable']; - $joinAlias = $this->fullTableName($assocData['joinTable']); - } - $query = array( - 'conditions' => $assocData['conditions'], - 'limit' => $assocData['limit'], - 'offset' => $assocData['offset'], - 'table' => $this->fullTableName($linkModel), - 'alias' => $association, - 'fields' => array_merge($this->fields($linkModel, $association, $assocData['fields']), $joinFields), - 'order' => $assocData['order'], - 'group' => null, - 'joins' => array(array( - 'table' => $joinTbl, - 'alias' => $joinAssoc, - 'conditions' => $this->getConstraint('hasAndBelongsToMany', $model, $linkModel, $joinAlias, $assocData, $association) - )) - ); - break; - } - if (isset($query)) { - return $this->buildStatement($query, $model); - } - return null; - } - -/** - * Returns a conditions array for the constraint between two models - * - * @param string $type Association type - * @param Model $model Model object - * @param string $linkModel - * @param string $alias - * @param array $assoc - * @param string $alias2 - * @return array Conditions array defining the constraint between $model and $association - */ - public function getConstraint($type, $model, $linkModel, $alias, $assoc, $alias2 = null) { - $assoc += array('external' => false, 'self' => false); - - if (empty($assoc['foreignKey'])) { - return array(); - } - - switch (true) { - case ($assoc['external'] && $type === 'hasOne'): - return array("{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'); - case ($assoc['external'] && $type === 'belongsTo'): - return array("{$alias}.{$linkModel->primaryKey}" => '{$__cakeForeignKey__$}'); - case (!$assoc['external'] && $type === 'hasOne'): - return array("{$alias}.{$assoc['foreignKey']}" => $this->identifier("{$model->alias}.{$model->primaryKey}")); - case (!$assoc['external'] && $type === 'belongsTo'): - return array("{$model->alias}.{$assoc['foreignKey']}" => $this->identifier("{$alias}.{$linkModel->primaryKey}")); - case ($type === 'hasMany'): - return array("{$alias}.{$assoc['foreignKey']}" => array('{$__cakeID__$}')); - case ($type === 'hasAndBelongsToMany'): - return array( - array("{$alias}.{$assoc['foreignKey']}" => '{$__cakeID__$}'), - array("{$alias}.{$assoc['associationForeignKey']}" => $this->identifier("{$alias2}.{$linkModel->primaryKey}")) - ); - } - return array(); - } - -/** - * Builds and generates a JOIN statement from an array. Handles final clean-up before conversion. - * - * @param array $join An array defining a JOIN statement in a query - * @return string An SQL JOIN statement to be used in a query - * @see DboSource::renderJoinStatement() - * @see DboSource::buildStatement() - */ - public function buildJoinStatement($join) { - $data = array_merge(array( - 'type' => null, - 'alias' => null, - 'table' => 'join_table', - 'conditions' => array() + /** + * Builds and generates a JOIN statement from an array. Handles final clean-up before conversion. + * + * @param array $join An array defining a JOIN statement in a query + * @return string An SQL JOIN statement to be used in a query + * @see DboSource::renderJoinStatement() + * @see DboSource::buildStatement() + */ + public function buildJoinStatement($join) { + $data = array_merge(array( + 'type' => null, + 'alias' => null, + 'table' => 'join_table', + 'conditions' => array() ), $join); - if (!empty($data['alias'])) { - $data['alias'] = $this->alias . $this->name($data['alias']); - } - if (!empty($data['conditions'])) { - $data['conditions'] = trim($this->conditions($data['conditions'], true, false)); - } - if (!empty($data['table']) && (!is_string($data['table']) || strpos($data['table'], '(') !== 0)) { - $data['table'] = $this->fullTableName($data['table']); - } - return $this->renderJoinStatement($data); + if (!empty($data['alias'])) { + $data['alias'] = $this->alias . $this->name($data['alias']); } + if (!empty($data['conditions'])) { + $data['conditions'] = trim($this->conditions($data['conditions'], true, false)); + } + if (!empty($data['table']) && (!is_string($data['table']) || strpos($data['table'], '(') !== 0)) { + $data['table'] = $this->fullTableName($data['table']); + } + return $this->renderJoinStatement($data); + } -/** - * Builds and generates an SQL statement from an array. Handles final clean-up before conversion. - * - * @param array $query An array defining an SQL query - * @param Model $model The model object which initiated the query - * @return string An executable SQL statement - * @see DboSource::renderStatement() - */ - public function buildStatement($query, $model) { - $query = array_merge($this->_queryDefaults, $query); - if (!empty($query['joins'])) { - $count = count($query['joins']); - for ($i = 0; $i < $count; $i++) { - if (is_array($query['joins'][$i])) { - $query['joins'][$i] = $this->buildJoinStatement($query['joins'][$i]); - } - } + /** + * Builds and generates an SQL statement from an array. Handles final clean-up before conversion. + * + * @param array $query An array defining an SQL query + * @param Model $model The model object which initiated the query + * @return string An executable SQL statement + * @see DboSource::renderStatement() + */ + public function buildStatement($query, $model) { + $query = array_merge($this->_queryDefaults, $query); + if (!empty($query['joins'])) { + $count = count($query['joins']); + for ($i = 0; $i < $count; $i++) { + if (is_array($query['joins'][$i])) { + $query['joins'][$i] = $this->buildJoinStatement($query['joins'][$i]); } - return $this->renderStatement('select', array( - 'conditions' => $this->conditions($query['conditions'], true, true, $model), - 'fields' => implode(', ', $query['fields']), - 'table' => $query['table'], - 'alias' => $this->alias . $this->name($query['alias']), - 'order' => $this->order($query['order'], 'ASC', $model), - 'limit' => $this->limit($query['limit'], $query['offset']), - 'joins' => implode(' ', $query['joins']), - 'group' => $this->group($query['group'], $model) + } + } + return $this->renderStatement('select', array( + 'conditions' => $this->conditions($query['conditions'], true, true, $model), + 'fields' => implode(', ', $query['fields']), + 'table' => $query['table'], + 'alias' => $this->alias . $this->name($query['alias']), + 'order' => $this->order($query['order'], 'ASC', $model), + 'limit' => $this->limit($query['limit'], $query['offset']), + 'joins' => implode(' ', $query['joins']), + 'group' => $this->group($query['group'], $model) )); + } + + /** + * Renders a final SQL JOIN statement + * + * @param array $data + * @return string + */ + public function renderJoinStatement($data) { + extract($data); + return trim("{$type} JOIN {$table} {$alias} ON ({$conditions})"); + } + + /** + * Renders a final SQL statement by putting together the component parts in the correct order + * + * @param string $type type of query being run. e.g select, create, update, delete, schema, alter. + * @param array $data Array of data to insert into the query. + * @return string Rendered SQL expression to be run. + */ + public function renderStatement($type, $data) { + extract($data); + $aliases = null; + + switch (strtolower($type)) { + case 'select': + return "SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}"; + case 'create': + return "INSERT INTO {$table} ({$fields}) VALUES ({$values})"; + case 'update': + if (!empty($alias)) { + $aliases = "{$this->alias}{$alias} {$joins} "; + } + return "UPDATE {$table} {$aliases}SET {$fields} {$conditions}"; + case 'delete': + if (!empty($alias)) { + $aliases = "{$this->alias}{$alias} {$joins} "; + } + return "DELETE {$alias} FROM {$table} {$aliases}{$conditions}"; + case 'schema': + foreach (array('columns', 'indexes', 'tableParameters') as $var) { + if (is_array(${$var})) { + ${$var} = "\t" . implode(",\n\t", array_filter(${$var})); + } else { + ${$var} = ''; + } + } + if (trim($indexes) !== '') { + $columns .= ','; + } + return "CREATE TABLE {$table} (\n{$columns}{$indexes}) {$tableParameters};"; + case 'alter': + return; + } + } + + /** + * Merges a mixed set of string/array conditions + * + * @param mixed $query + * @param mixed $assoc + * @return array + */ + protected function _mergeConditions($query, $assoc) { + if (empty($assoc)) { + return $query; } -/** - * Renders a final SQL JOIN statement - * - * @param array $data - * @return string - */ - public function renderJoinStatement($data) { - extract($data); - return trim("{$type} JOIN {$table} {$alias} ON ({$conditions})"); + if (is_array($query)) { + return array_merge((array) $assoc, $query); } -/** - * Renders a final SQL statement by putting together the component parts in the correct order - * - * @param string $type type of query being run. e.g select, create, update, delete, schema, alter. - * @param array $data Array of data to insert into the query. - * @return string Rendered SQL expression to be run. - */ - public function renderStatement($type, $data) { - extract($data); - $aliases = null; - - switch (strtolower($type)) { - case 'select': - return "SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}"; - case 'create': - return "INSERT INTO {$table} ({$fields}) VALUES ({$values})"; - case 'update': - if (!empty($alias)) { - $aliases = "{$this->alias}{$alias} {$joins} "; - } - return "UPDATE {$table} {$aliases}SET {$fields} {$conditions}"; - case 'delete': - if (!empty($alias)) { - $aliases = "{$this->alias}{$alias} {$joins} "; - } - return "DELETE {$alias} FROM {$table} {$aliases}{$conditions}"; - case 'schema': - foreach (array('columns', 'indexes', 'tableParameters') as $var) { - if (is_array(${$var})) { - ${$var} = "\t" . implode(",\n\t", array_filter(${$var})); - } else { - ${$var} = ''; - } - } - if (trim($indexes) !== '') { - $columns .= ','; - } - return "CREATE TABLE {$table} (\n{$columns}{$indexes}) {$tableParameters};"; - case 'alter': - return; - } + if (!empty($query)) { + $query = array($query); + if (is_array($assoc)) { + $query = array_merge($query, $assoc); + } else { + $query[] = $assoc; + } + return $query; } -/** - * Merges a mixed set of string/array conditions - * - * @param mixed $query - * @param mixed $assoc - * @return array - */ - protected function _mergeConditions($query, $assoc) { - if (empty($assoc)) { - return $query; - } + return $assoc; + } - if (is_array($query)) { - return array_merge((array)$assoc, $query); - } - - if (!empty($query)) { - $query = array($query); - if (is_array($assoc)) { - $query = array_merge($query, $assoc); - } else { - $query[] = $assoc; - } - return $query; - } - - return $assoc; + /** + * Generates and executes an SQL UPDATE statement for given model, fields, and values. + * For databases that do not support aliases in UPDATE queries. + * + * @param Model $model + * @param array $fields + * @param array $values + * @param mixed $conditions + * @return boolean Success + */ + public function update(Model $model, $fields = array(), $values = null, $conditions = null) { + if (!$values) { + $combined = $fields; + } else { + $combined = array_combine($fields, $values); } -/** - * Generates and executes an SQL UPDATE statement for given model, fields, and values. - * For databases that do not support aliases in UPDATE queries. - * - * @param Model $model - * @param array $fields - * @param array $values - * @param mixed $conditions - * @return boolean Success - */ - public function update(Model $model, $fields = array(), $values = null, $conditions = null) { - if (!$values) { - $combined = $fields; - } else { - $combined = array_combine($fields, $values); - } + $fields = implode(', ', $this->_prepareUpdateFields($model, $combined, empty($conditions))); - $fields = implode(', ', $this->_prepareUpdateFields($model, $combined, empty($conditions))); + $alias = $joins = null; + $table = $this->fullTableName($model); + $conditions = $this->_matchRecords($model, $conditions); - $alias = $joins = null; - $table = $this->fullTableName($model); - $conditions = $this->_matchRecords($model, $conditions); - - if ($conditions === false) { - return false; - } - $query = compact('table', 'alias', 'joins', 'fields', 'conditions'); - - if (!$this->execute($this->renderStatement('update', $query))) { - $model->onError(); - return false; - } - return true; + if ($conditions === false) { + return false; } + $query = compact('table', 'alias', 'joins', 'fields', 'conditions'); -/** - * Quotes and prepares fields and values for an SQL UPDATE statement - * - * @param Model $model - * @param array $fields - * @param boolean $quoteValues If values should be quoted, or treated as SQL snippets - * @param boolean $alias Include the model alias in the field name - * @return array Fields and values, quoted and prepared - */ - protected function _prepareUpdateFields(Model $model, $fields, $quoteValues = true, $alias = false) { - $quotedAlias = $this->startQuote . $model->alias . $this->endQuote; + if (!$this->execute($this->renderStatement('update', $query))) { + $model->onError(); + return false; + } + return true; + } - $updates = array(); - foreach ($fields as $field => $value) { - if ($alias && strpos($field, '.') === false) { - $quoted = $model->escapeField($field); - } elseif (!$alias && strpos($field, '.') !== false) { - $quoted = $this->name(str_replace($quotedAlias . '.', '', str_replace( + /** + * Quotes and prepares fields and values for an SQL UPDATE statement + * + * @param Model $model + * @param array $fields + * @param boolean $quoteValues If values should be quoted, or treated as SQL snippets + * @param boolean $alias Include the model alias in the field name + * @return array Fields and values, quoted and prepared + */ + protected function _prepareUpdateFields(Model $model, $fields, $quoteValues = true, $alias = false) { + $quotedAlias = $this->startQuote . $model->alias . $this->endQuote; + + $updates = array(); + foreach ($fields as $field => $value) { + if ($alias && strpos($field, '.') === false) { + $quoted = $model->escapeField($field); + } elseif (!$alias && strpos($field, '.') !== false) { + $quoted = $this->name(str_replace($quotedAlias . '.', '', str_replace( $model->alias . '.', '', $field ))); - } else { - $quoted = $this->name($field); - } + } else { + $quoted = $this->name($field); + } - if ($value === null) { - $updates[] = $quoted . ' = NULL'; - continue; - } - $update = $quoted . ' = '; + if ($value === null) { + $updates[] = $quoted . ' = NULL'; + continue; + } + $update = $quoted . ' = '; - if ($quoteValues) { - $update .= $this->value($value, $model->getColumnType($field)); - } elseif ($model->getColumnType($field) === 'boolean' && (is_int($value) || is_bool($value))) { - $update .= $this->boolean($value, true); - } elseif (!$alias) { - $update .= str_replace($quotedAlias . '.', '', str_replace( - $model->alias . '.', '', $value - )); - } else { - $update .= $value; - } - $updates[] = $update; - } - return $updates; - } - -/** - * Generates and executes an SQL DELETE statement. - * For databases that do not support aliases in UPDATE queries. - * - * @param Model $model - * @param mixed $conditions - * @return boolean Success - */ - public function delete(Model $model, $conditions = null) { - $alias = $joins = null; - $table = $this->fullTableName($model); - $conditions = $this->_matchRecords($model, $conditions); - - if ($conditions === false) { - return false; - } - - if ($this->execute($this->renderStatement('delete', compact('alias', 'table', 'joins', 'conditions'))) === false) { - $model->onError(); - return false; - } - return true; - } - -/** - * Gets a list of record IDs for the given conditions. Used for multi-record updates and deletes - * in databases that do not support aliases in UPDATE/DELETE queries. - * - * @param Model $model - * @param mixed $conditions - * @return array List of record IDs - */ - protected function _matchRecords(Model $model, $conditions = null) { - if ($conditions === true) { - $conditions = $this->conditions(true); - } elseif ($conditions === null) { - $conditions = $this->conditions($this->defaultConditions($model, $conditions, false), true, true, $model); - } else { - $noJoin = true; - foreach ($conditions as $field => $value) { - $originalField = $field; - if (strpos($field, '.') !== false) { - list(, $field) = explode('.', $field); - $field = ltrim($field, $this->startQuote); - $field = rtrim($field, $this->endQuote); - } - if (!$model->hasField($field)) { - $noJoin = false; - break; - } - if ($field !== $originalField) { - $conditions[$field] = $value; - unset($conditions[$originalField]); - } - } - if ($noJoin === true) { - return $this->conditions($conditions); - } - $idList = $model->find('all', array( - 'fields' => "{$model->alias}.{$model->primaryKey}", - 'conditions' => $conditions + if ($quoteValues) { + $update .= $this->value($value, $model->getColumnType($field)); + } elseif ($model->getColumnType($field) === 'boolean' && (is_int($value) || is_bool($value))) { + $update .= $this->boolean($value, true); + } elseif (!$alias) { + $update .= str_replace($quotedAlias . '.', '', str_replace( + $model->alias . '.', '', $value )); + } else { + $update .= $value; + } + $updates[] = $update; + } + return $updates; + } - if (empty($idList)) { - return false; - } - $conditions = $this->conditions(array( - $model->primaryKey => Hash::extract($idList, "{n}.{$model->alias}.{$model->primaryKey}") - )); + /** + * Generates and executes an SQL DELETE statement. + * For databases that do not support aliases in UPDATE queries. + * + * @param Model $model + * @param mixed $conditions + * @return boolean Success + */ + public function delete(Model $model, $conditions = null) { + $alias = $joins = null; + $table = $this->fullTableName($model); + $conditions = $this->_matchRecords($model, $conditions); + + if ($conditions === false) { + return false; + } + + if ($this->execute($this->renderStatement('delete', compact('alias', 'table', 'joins', 'conditions'))) === false) { + $model->onError(); + return false; + } + return true; + } + + /** + * Gets a list of record IDs for the given conditions. Used for multi-record updates and deletes + * in databases that do not support aliases in UPDATE/DELETE queries. + * + * @param Model $model + * @param mixed $conditions + * @return array List of record IDs + */ + protected function _matchRecords(Model $model, $conditions = null) { + if ($conditions === true) { + $conditions = $this->conditions(true); + } elseif ($conditions === null) { + $conditions = $this->conditions($this->defaultConditions($model, $conditions, false), true, true, $model); + } else { + $noJoin = true; + foreach ($conditions as $field => $value) { + $originalField = $field; + if (strpos($field, '.') !== false) { + list(, $field) = explode('.', $field); + $field = ltrim($field, $this->startQuote); + $field = rtrim($field, $this->endQuote); } - return $conditions; - } - -/** - * Returns an array of SQL JOIN fragments from a model's associations - * - * @param Model $model - * @return array - */ - protected function _getJoins(Model $model) { - $join = array(); - $joins = array_merge($model->getAssociated('hasOne'), $model->getAssociated('belongsTo')); - - foreach ($joins as $assoc) { - if (isset($model->{$assoc}) && $model->useDbConfig == $model->{$assoc}->useDbConfig && $model->{$assoc}->getDataSource()) { - $assocData = $model->getAssociated($assoc); - $join[] = $this->buildJoinStatement(array( - 'table' => $model->{$assoc}, - 'alias' => $assoc, - 'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT', - 'conditions' => trim($this->conditions( - $this->_mergeConditions($assocData['conditions'], $this->getConstraint($assocData['association'], $model, $model->{$assoc}, $assoc, $assocData)), - true, false, $model - )) - )); - } + if (!$model->hasField($field)) { + $noJoin = false; + break; } - return $join; - } - -/** - * Returns an SQL calculation, i.e. COUNT() or MAX() - * - * @param Model $model - * @param string $func Lowercase name of SQL function, i.e. 'count' or 'max' - * @param array $params Function parameters (any values must be quoted manually) - * @return string An SQL calculation function - */ - public function calculate(Model $model, $func, $params = array()) { - $params = (array)$params; - - switch (strtolower($func)) { - case 'count': - if (!isset($params[0])) { - $params[0] = '*'; - } - if (!isset($params[1])) { - $params[1] = 'count'; - } - if (is_object($model) && $model->isVirtualField($params[0])) { - $arg = $this->_quoteFields($model->getVirtualField($params[0])); - } else { - $arg = $this->name($params[0]); - } - return 'COUNT(' . $arg . ') AS ' . $this->name($params[1]); - case 'max': - case 'min': - if (!isset($params[1])) { - $params[1] = $params[0]; - } - if (is_object($model) && $model->isVirtualField($params[0])) { - $arg = $this->_quoteFields($model->getVirtualField($params[0])); - } else { - $arg = $this->name($params[0]); - } - return strtoupper($func) . '(' . $arg . ') AS ' . $this->name($params[1]); + if ($field !== $originalField) { + $conditions[$field] = $value; + unset($conditions[$originalField]); } - } + } + if ($noJoin === true) { + return $this->conditions($conditions); + } + $idList = $model->find('all', array( + 'fields' => "{$model->alias}.{$model->primaryKey}", + 'conditions' => $conditions + )); -/** - * Deletes all the records in a table and resets the count of the auto-incrementing - * primary key, where applicable. - * - * @param Model|string $table A string or model class representing the table to be truncated - * @return boolean SQL TRUNCATE TABLE statement, false if not applicable. - */ - public function truncate($table) { - return $this->execute('TRUNCATE TABLE ' . $this->fullTableName($table)); - } - -/** - * Check if the server support nested transactions - * - * @return boolean - */ - public function nestedTransactionSupported() { + if (empty($idList)) { return false; + } + $conditions = $this->conditions(array( + $model->primaryKey => Hash::extract($idList, "{n}.{$model->alias}.{$model->primaryKey}") + )); + } + return $conditions; + } + + /** + * Returns an array of SQL JOIN fragments from a model's associations + * + * @param Model $model + * @return array + */ + protected function _getJoins(Model $model) { + $join = array(); + $joins = array_merge($model->getAssociated('hasOne'), $model->getAssociated('belongsTo')); + + foreach ($joins as $assoc) { + if (isset($model->{$assoc}) && $model->useDbConfig == $model->{$assoc}->useDbConfig && $model->{$assoc}->getDataSource()) { + $assocData = $model->getAssociated($assoc); + $join[] = $this->buildJoinStatement(array( + 'table' => $model->{$assoc}, + 'alias' => $assoc, + 'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT', + 'conditions' => trim($this->conditions( + $this->_mergeConditions($assocData['conditions'], $this->getConstraint($assocData['association'], $model, $model->{$assoc}, $assoc, $assocData)), true, false, $model + )) + )); + } + } + return $join; + } + + /** + * Returns an SQL calculation, i.e. COUNT() or MAX() + * + * @param Model $model + * @param string $func Lowercase name of SQL function, i.e. 'count' or 'max' + * @param array $params Function parameters (any values must be quoted manually) + * @return string An SQL calculation function + */ + public function calculate(Model $model, $func, $params = array()) { + $params = (array) $params; + + switch (strtolower($func)) { + case 'count': + if (!isset($params[0])) { + $params[0] = '*'; + } + if (!isset($params[1])) { + $params[1] = 'count'; + } + if (is_object($model) && $model->isVirtualField($params[0])) { + $arg = $this->_quoteFields($model->getVirtualField($params[0])); + } else { + $arg = $this->name($params[0]); + } + return 'COUNT(' . $arg . ') AS ' . $this->name($params[1]); + case 'max': + case 'min': + if (!isset($params[1])) { + $params[1] = $params[0]; + } + if (is_object($model) && $model->isVirtualField($params[0])) { + $arg = $this->_quoteFields($model->getVirtualField($params[0])); + } else { + $arg = $this->name($params[0]); + } + return strtoupper($func) . '(' . $arg . ') AS ' . $this->name($params[1]); + } + } + + /** + * Deletes all the records in a table and resets the count of the auto-incrementing + * primary key, where applicable. + * + * @param Model|string $table A string or model class representing the table to be truncated + * @return boolean SQL TRUNCATE TABLE statement, false if not applicable. + */ + public function truncate($table) { + return $this->execute('TRUNCATE TABLE ' . $this->fullTableName($table)); + } + + /** + * Check if the server support nested transactions + * + * @return boolean + */ + public function nestedTransactionSupported() { + return false; + } + + /** + * Begin a transaction + * + * @return boolean True on success, false on fail + * (i.e. if the database/model does not support transactions, + * or a transaction has not started). + */ + public function begin() { + if ($this->_transactionStarted) { + if ($this->nestedTransactionSupported()) { + return $this->_beginNested(); + } + $this->_transactionNesting++; + return $this->_transactionStarted; } -/** - * Begin a transaction - * - * @return boolean True on success, false on fail - * (i.e. if the database/model does not support transactions, - * or a transaction has not started). - */ - public function begin() { - if ($this->_transactionStarted) { - if ($this->nestedTransactionSupported()) { - return $this->_beginNested(); - } - $this->_transactionNesting++; - return $this->_transactionStarted; - } + $this->_transactionNesting = 0; + if ($this->fullDebug) { + $this->logQuery('BEGIN'); + } + return $this->_transactionStarted = $this->_connection->beginTransaction(); + } - $this->_transactionNesting = 0; - if ($this->fullDebug) { - $this->logQuery('BEGIN'); - } - return $this->_transactionStarted = $this->_connection->beginTransaction(); + /** + * Begin a nested transaction + * + * @return boolean + */ + protected function _beginNested() { + $query = 'SAVEPOINT LEVEL' . ++$this->_transactionNesting; + if ($this->fullDebug) { + $this->logQuery($query); + } + $this->_connection->exec($query); + return true; + } + + /** + * Commit a transaction + * + * @return boolean True on success, false on fail + * (i.e. if the database/model does not support transactions, + * or a transaction has not started). + */ + public function commit() { + if (!$this->_transactionStarted) { + return false; } -/** - * Begin a nested transaction - * - * @return boolean - */ - protected function _beginNested() { - $query = 'SAVEPOINT LEVEL' . ++$this->_transactionNesting; - if ($this->fullDebug) { - $this->logQuery($query); - } - $this->_connection->exec($query); - return true; + if ($this->_transactionNesting === 0) { + if ($this->fullDebug) { + $this->logQuery('COMMIT'); + } + $this->_transactionStarted = false; + return $this->_connection->commit(); } -/** - * Commit a transaction - * - * @return boolean True on success, false on fail - * (i.e. if the database/model does not support transactions, - * or a transaction has not started). - */ - public function commit() { - if (!$this->_transactionStarted) { - return false; - } - - if ($this->_transactionNesting === 0) { - if ($this->fullDebug) { - $this->logQuery('COMMIT'); - } - $this->_transactionStarted = false; - return $this->_connection->commit(); - } - - if ($this->nestedTransactionSupported()) { - return $this->_commitNested(); - } - - $this->_transactionNesting--; - return true; + if ($this->nestedTransactionSupported()) { + return $this->_commitNested(); } -/** - * Commit a nested transaction - * - * @return boolean - */ - protected function _commitNested() { - $query = 'RELEASE SAVEPOINT LEVEL' . $this->_transactionNesting--; - if ($this->fullDebug) { - $this->logQuery($query); - } - $this->_connection->exec($query); - return true; + $this->_transactionNesting--; + return true; + } + + /** + * Commit a nested transaction + * + * @return boolean + */ + protected function _commitNested() { + $query = 'RELEASE SAVEPOINT LEVEL' . $this->_transactionNesting--; + if ($this->fullDebug) { + $this->logQuery($query); + } + $this->_connection->exec($query); + return true; + } + + /** + * Rollback a transaction + * + * @return boolean True on success, false on fail + * (i.e. if the database/model does not support transactions, + * or a transaction has not started). + */ + public function rollback() { + if (!$this->_transactionStarted) { + return false; } -/** - * Rollback a transaction - * - * @return boolean True on success, false on fail - * (i.e. if the database/model does not support transactions, - * or a transaction has not started). - */ - public function rollback() { - if (!$this->_transactionStarted) { - return false; - } - - if ($this->_transactionNesting === 0) { - if ($this->fullDebug) { - $this->logQuery('ROLLBACK'); - } - $this->_transactionStarted = false; - return $this->_connection->rollBack(); - } - - if ($this->nestedTransactionSupported()) { - return $this->_rollbackNested(); - } - - $this->_transactionNesting--; - return true; + if ($this->_transactionNesting === 0) { + if ($this->fullDebug) { + $this->logQuery('ROLLBACK'); + } + $this->_transactionStarted = false; + return $this->_connection->rollBack(); } -/** - * Rollback a nested transaction - * - * @return boolean - */ - protected function _rollbackNested() { - $query = 'ROLLBACK TO SAVEPOINT LEVEL' . $this->_transactionNesting--; - if ($this->fullDebug) { - $this->logQuery($query); - } - $this->_connection->exec($query); - return true; + if ($this->nestedTransactionSupported()) { + return $this->_rollbackNested(); } -/** - * Returns the ID generated from the previous INSERT operation. - * - * @param mixed $source - * @return mixed - */ - public function lastInsertId($source = null) { - return $this->_connection->lastInsertId(); + $this->_transactionNesting--; + return true; + } + + /** + * Rollback a nested transaction + * + * @return boolean + */ + protected function _rollbackNested() { + $query = 'ROLLBACK TO SAVEPOINT LEVEL' . $this->_transactionNesting--; + if ($this->fullDebug) { + $this->logQuery($query); } + $this->_connection->exec($query); + return true; + } -/** - * Creates a default set of conditions from the model if $conditions is null/empty. - * If conditions are supplied then they will be returned. If a model doesn't exist and no conditions - * were provided either null or false will be returned based on what was input. - * - * @param Model $model - * @param string|array|boolean $conditions Array of conditions, conditions string, null or false. If an array of conditions, - * or string conditions those conditions will be returned. With other values the model's existence will be checked. - * If the model doesn't exist a null or false will be returned depending on the input value. - * @param boolean $useAlias Use model aliases rather than table names when generating conditions - * @return mixed Either null, false, $conditions or an array of default conditions to use. - * @see DboSource::update() - * @see DboSource::conditions() - */ - public function defaultConditions(Model $model, $conditions, $useAlias = true) { - if (!empty($conditions)) { - return $conditions; - } - $exists = $model->exists(); - if (!$exists && $conditions !== null) { - return false; - } elseif (!$exists) { - return null; - } - $alias = $model->alias; + /** + * Returns the ID generated from the previous INSERT operation. + * + * @param mixed $source + * @return mixed + */ + public function lastInsertId($source = null) { + return $this->_connection->lastInsertId(); + } - if (!$useAlias) { - $alias = $this->fullTableName($model, false); - } - return array("{$alias}.{$model->primaryKey}" => $model->getID()); + /** + * Creates a default set of conditions from the model if $conditions is null/empty. + * If conditions are supplied then they will be returned. If a model doesn't exist and no conditions + * were provided either null or false will be returned based on what was input. + * + * @param Model $model + * @param string|array|boolean $conditions Array of conditions, conditions string, null or false. If an array of conditions, + * or string conditions those conditions will be returned. With other values the model's existence will be checked. + * If the model doesn't exist a null or false will be returned depending on the input value. + * @param boolean $useAlias Use model aliases rather than table names when generating conditions + * @return mixed Either null, false, $conditions or an array of default conditions to use. + * @see DboSource::update() + * @see DboSource::conditions() + */ + public function defaultConditions(Model $model, $conditions, $useAlias = true) { + if (!empty($conditions)) { + return $conditions; } - -/** - * Returns a key formatted like a string Model.fieldname(i.e. Post.title, or Country.name) - * - * @param Model $model - * @param string $key - * @param string $assoc - * @return string - */ - public function resolveKey(Model $model, $key, $assoc = null) { - if (strpos('.', $key) !== false) { - return $this->name($model->alias) . '.' . $this->name($key); - } - return $key; + $exists = $model->exists(); + if (!$exists && $conditions !== null) { + return false; + } elseif (!$exists) { + return null; } + $alias = $model->alias; -/** - * Private helper method to remove query metadata in given data array. - * - * @param array $data - * @return array - */ - protected function _scrubQueryData($data) { - static $base = null; - if ($base === null) { - $base = array_fill_keys(array('conditions', 'fields', 'joins', 'order', 'limit', 'offset', 'group'), array()); - $base['callbacks'] = null; - } - return (array)$data + $base; + if (!$useAlias) { + $alias = $this->fullTableName($model, false); } + return array("{$alias}.{$model->primaryKey}" => $model->getID()); + } -/** - * Converts model virtual fields into sql expressions to be fetched later - * - * @param Model $model - * @param string $alias Alias table name - * @param array $fields virtual fields to be used on query - * @return array - */ - protected function _constructVirtualFields(Model $model, $alias, $fields) { - $virtual = array(); - foreach ($fields as $field) { - $virtualField = $this->name($alias . $this->virtualFieldSeparator . $field); - $expression = $this->_quoteFields($model->getVirtualField($field)); - $virtual[] = '(' . $expression . ") {$this->alias} {$virtualField}"; - } - return $virtual; + /** + * Returns a key formatted like a string Model.fieldname(i.e. Post.title, or Country.name) + * + * @param Model $model + * @param string $key + * @param string $assoc + * @return string + */ + public function resolveKey(Model $model, $key, $assoc = null) { + if (strpos('.', $key) !== false) { + return $this->name($model->alias) . '.' . $this->name($key); } + return $key; + } -/** - * Generates the fields list of an SQL query. - * - * @param Model $model - * @param string $alias Alias table name - * @param mixed $fields - * @param boolean $quote If false, returns fields array unquoted - * @return array - */ - public function fields(Model $model, $alias = null, $fields = array(), $quote = true) { - if (empty($alias)) { - $alias = $model->alias; - } - $virtualFields = $model->getVirtualField(); - $cacheKey = array( - $alias, - get_class($model), - $model->alias, - $virtualFields, - $fields, - $quote, - ConnectionManager::getSourceName($this), - $model->table - ); - $cacheKey = md5(serialize($cacheKey)); - if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) { - return $return; - } - $allFields = empty($fields); - if ($allFields) { - $fields = array_keys($model->schema()); - } elseif (!is_array($fields)) { - $fields = String::tokenize($fields); - } - $fields = array_values(array_filter($fields)); - $allFields = $allFields || in_array('*', $fields) || in_array($model->alias . '.*', $fields); - - $virtual = array(); - if (!empty($virtualFields)) { - $virtualKeys = array_keys($virtualFields); - foreach ($virtualKeys as $field) { - $virtualKeys[] = $model->alias . '.' . $field; - } - $virtual = ($allFields) ? $virtualKeys : array_intersect($virtualKeys, $fields); - foreach ($virtual as $i => $field) { - if (strpos($field, '.') !== false) { - $virtual[$i] = str_replace($model->alias . '.', '', $field); - } - $fields = array_diff($fields, array($field)); - } - $fields = array_values($fields); - } - if (!$quote) { - if (!empty($virtual)) { - $fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual)); - } - return $fields; - } - $count = count($fields); - - if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) { - for ($i = 0; $i < $count; $i++) { - if (is_string($fields[$i]) && in_array($fields[$i], $virtual)) { - unset($fields[$i]); - continue; - } - if (is_object($fields[$i]) && isset($fields[$i]->type) && $fields[$i]->type === 'expression') { - $fields[$i] = $fields[$i]->value; - } elseif (preg_match('/^\(.*\)\s' . $this->alias . '.*/i', $fields[$i])) { - continue; - } elseif (!preg_match('/^.+\\(.*\\)/', $fields[$i])) { - $prepend = ''; - - if (strpos($fields[$i], 'DISTINCT') !== false) { - $prepend = 'DISTINCT '; - $fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i])); - } - $dot = strpos($fields[$i], '.'); - - if ($dot === false) { - $prefix = !( - strpos($fields[$i], ' ') !== false || - strpos($fields[$i], '(') !== false - ); - $fields[$i] = $this->name(($prefix ? $alias . '.' : '') . $fields[$i]); - } else { - if (strpos($fields[$i], ',') === false) { - $build = explode('.', $fields[$i]); - if (!Hash::numeric($build)) { - $fields[$i] = $this->name(implode('.', $build)); - } - } - } - $fields[$i] = $prepend . $fields[$i]; - } elseif (preg_match('/\(([\.\w]+)\)/', $fields[$i], $field)) { - if (isset($field[1])) { - if (strpos($field[1], '.') === false) { - $field[1] = $this->name($alias . '.' . $field[1]); - } else { - $field[0] = explode('.', $field[1]); - if (!Hash::numeric($field[0])) { - $field[0] = implode('.', array_map(array(&$this, 'name'), $field[0])); - $fields[$i] = preg_replace('/\(' . $field[1] . '\)/', '(' . $field[0] . ')', $fields[$i], 1); - } - } - } - } - } - } - if (!empty($virtual)) { - $fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual)); - } - return $this->cacheMethod(__FUNCTION__, $cacheKey, array_unique($fields)); + /** + * Private helper method to remove query metadata in given data array. + * + * @param array $data + * @return array + */ + protected function _scrubQueryData($data) { + static $base = null; + if ($base === null) { + $base = array_fill_keys(array('conditions', 'fields', 'joins', 'order', 'limit', 'offset', 'group'), array()); + $base['callbacks'] = null; } + return (array) $data + $base; + } -/** - * Creates a WHERE clause by parsing given conditions data. If an array or string - * conditions are provided those conditions will be parsed and quoted. If a boolean - * is given it will be integer cast as condition. Null will return 1 = 1. - * - * Results of this method are stored in a memory cache. This improves performance, but - * because the method uses a hashing algorithm it can have collisions. - * Setting DboSource::$cacheMethods to false will disable the memory cache. - * - * @param mixed $conditions Array or string of conditions, or any value. - * @param boolean $quoteValues If true, values should be quoted - * @param boolean $where If true, "WHERE " will be prepended to the return value - * @param Model $model A reference to the Model instance making the query - * @return string SQL fragment - */ - public function conditions($conditions, $quoteValues = true, $where = true, $model = null) { - $clause = $out = ''; - - if ($where) { - $clause = ' WHERE '; - } - - if (is_array($conditions) && !empty($conditions)) { - $out = $this->conditionKeysToString($conditions, $quoteValues, $model); - - if (empty($out)) { - return $clause . ' 1 = 1'; - } - return $clause . implode(' AND ', $out); - } - if (is_bool($conditions)) { - return $clause . (int)$conditions . ' = 1'; - } - - if (empty($conditions) || trim($conditions) === '') { - return $clause . '1 = 1'; - } - $clauses = '/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i'; - - if (preg_match($clauses, $conditions)) { - $clause = ''; - } - $conditions = $this->_quoteFields($conditions); - return $clause . $conditions; + /** + * Converts model virtual fields into sql expressions to be fetched later + * + * @param Model $model + * @param string $alias Alias table name + * @param array $fields virtual fields to be used on query + * @return array + */ + protected function _constructVirtualFields(Model $model, $alias, $fields) { + $virtual = array(); + foreach ($fields as $field) { + $virtualField = $this->name($alias . $this->virtualFieldSeparator . $field); + $expression = $this->_quoteFields($model->getVirtualField($field)); + $virtual[] = '(' . $expression . ") {$this->alias} {$virtualField}"; } + return $virtual; + } -/** - * Creates a WHERE clause by parsing given conditions array. Used by DboSource::conditions(). - * - * @param array $conditions Array or string of conditions - * @param boolean $quoteValues If true, values should be quoted - * @param Model $model A reference to the Model instance making the query - * @return string SQL fragment - */ - public function conditionKeysToString($conditions, $quoteValues = true, $model = null) { - $out = array(); - $data = $columnType = null; - $bool = array('and', 'or', 'not', 'and not', 'or not', 'xor', '||', '&&'); + /** + * Generates the fields list of an SQL query. + * + * @param Model $model + * @param string $alias Alias table name + * @param mixed $fields + * @param boolean $quote If false, returns fields array unquoted + * @return array + */ + public function fields(Model $model, $alias = null, $fields = array(), $quote = true) { + if (empty($alias)) { + $alias = $model->alias; + } + $virtualFields = $model->getVirtualField(); + $cacheKey = array( + $alias, + get_class($model), + $model->alias, + $virtualFields, + $fields, + $quote, + ConnectionManager::getSourceName($this), + $model->table + ); + $cacheKey = md5(serialize($cacheKey)); + if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) { + return $return; + } + $allFields = empty($fields); + if ($allFields) { + $fields = array_keys($model->schema()); + } elseif (!is_array($fields)) { + $fields = String::tokenize($fields); + } + $fields = array_values(array_filter($fields)); + $allFields = $allFields || in_array('*', $fields) || in_array($model->alias . '.*', $fields); - foreach ($conditions as $key => $value) { - $join = ' AND '; - $not = null; + $virtual = array(); + if (!empty($virtualFields)) { + $virtualKeys = array_keys($virtualFields); + foreach ($virtualKeys as $field) { + $virtualKeys[] = $model->alias . '.' . $field; + } + $virtual = ($allFields) ? $virtualKeys : array_intersect($virtualKeys, $fields); + foreach ($virtual as $i => $field) { + if (strpos($field, '.') !== false) { + $virtual[$i] = str_replace($model->alias . '.', '', $field); + } + $fields = array_diff($fields, array($field)); + } + $fields = array_values($fields); + } + if (!$quote) { + if (!empty($virtual)) { + $fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual)); + } + return $fields; + } + $count = count($fields); - if (is_array($value)) { - $valueInsert = ( - !empty($value) && - (substr_count($key, '?') === count($value) || substr_count($key, ':') === count($value)) + if ($count >= 1 && !in_array($fields[0], array('*', 'COUNT(*)'))) { + for ($i = 0; $i < $count; $i++) { + if (is_string($fields[$i]) && in_array($fields[$i], $virtual)) { + unset($fields[$i]); + continue; + } + if (is_object($fields[$i]) && isset($fields[$i]->type) && $fields[$i]->type === 'expression') { + $fields[$i] = $fields[$i]->value; + } elseif (preg_match('/^\(.*\)\s' . $this->alias . '.*/i', $fields[$i])) { + continue; + } elseif (!preg_match('/^.+\\(.*\\)/', $fields[$i])) { + $prepend = ''; + + if (strpos($fields[$i], 'DISTINCT') !== false) { + $prepend = 'DISTINCT '; + $fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i])); + } + $dot = strpos($fields[$i], '.'); + + if ($dot === false) { + $prefix = !( + strpos($fields[$i], ' ') !== false || + strpos($fields[$i], '(') !== false ); + $fields[$i] = $this->name(($prefix ? $alias . '.' : '') . $fields[$i]); + } else { + if (strpos($fields[$i], ',') === false) { + $build = explode('.', $fields[$i]); + if (!Hash::numeric($build)) { + $fields[$i] = $this->name(implode('.', $build)); + } } - - if (is_numeric($key) && empty($value)) { - continue; - } elseif (is_numeric($key) && is_string($value)) { - $out[] = $this->_quoteFields($value); - } elseif ((is_numeric($key) && is_array($value)) || in_array(strtolower(trim($key)), $bool)) { - if (in_array(strtolower(trim($key)), $bool)) { - $join = ' ' . strtoupper($key) . ' '; - } else { - $key = $join; - } - $value = $this->conditionKeysToString($value, $quoteValues, $model); - - if (strpos($join, 'NOT') !== false) { - if (strtoupper(trim($key)) === 'NOT') { - $key = 'AND ' . trim($key); - } - $not = 'NOT '; - } - - if (empty($value)) { - continue; - } - - if (empty($value[1])) { - if ($not) { - $out[] = $not . '(' . $value[0] . ')'; - } else { - $out[] = $value[0]; - } - } else { - $out[] = '(' . $not . '(' . implode(') ' . strtoupper($key) . ' (', $value) . '))'; - } + } + $fields[$i] = $prepend . $fields[$i]; + } elseif (preg_match('/\(([\.\w]+)\)/', $fields[$i], $field)) { + if (isset($field[1])) { + if (strpos($field[1], '.') === false) { + $field[1] = $this->name($alias . '.' . $field[1]); } else { - if (is_object($value) && isset($value->type)) { - if ($value->type === 'identifier') { - $data .= $this->name($key) . ' = ' . $this->name($value->value); - } elseif ($value->type === 'expression') { - if (is_numeric($key)) { - $data .= $value->value; - } else { - $data .= $this->name($key) . ' = ' . $value->value; - } - } - } elseif (is_array($value) && !empty($value) && !$valueInsert) { - $keys = array_keys($value); - if ($keys === array_values($keys)) { - $count = count($value); - if ($count === 1 && !preg_match("/\s+NOT$/", $key)) { - $data = $this->_quoteFields($key) . ' = ('; - if ($quoteValues) { - if (is_object($model)) { - $columnType = $model->getColumnType($key); - } - $data .= implode(', ', $this->value($value, $columnType)); - } - $data .= ')'; - } else { - $data = $this->_parseKey($model, $key, $value); - } - } else { - $ret = $this->conditionKeysToString($value, $quoteValues, $model); - if (count($ret) > 1) { - $data = '(' . implode(') AND (', $ret) . ')'; - } elseif (isset($ret[0])) { - $data = $ret[0]; - } - } - } elseif (is_numeric($key) && !empty($value)) { - $data = $this->_quoteFields($value); - } else { - $data = $this->_parseKey($model, trim($key), $value); - } - - if ($data) { - $out[] = $data; - $data = null; - } + $field[0] = explode('.', $field[1]); + if (!Hash::numeric($field[0])) { + $field[0] = implode('.', array_map(array(&$this, 'name'), $field[0])); + $fields[$i] = preg_replace('/\(' . $field[1] . '\)/', '(' . $field[0] . ')', $fields[$i], 1); + } } + } } - return $out; + } + } + if (!empty($virtual)) { + $fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual)); + } + return $this->cacheMethod(__FUNCTION__, $cacheKey, array_unique($fields)); + } + + /** + * Creates a WHERE clause by parsing given conditions data. If an array or string + * conditions are provided those conditions will be parsed and quoted. If a boolean + * is given it will be integer cast as condition. Null will return 1 = 1. + * + * Results of this method are stored in a memory cache. This improves performance, but + * because the method uses a hashing algorithm it can have collisions. + * Setting DboSource::$cacheMethods to false will disable the memory cache. + * + * @param mixed $conditions Array or string of conditions, or any value. + * @param boolean $quoteValues If true, values should be quoted + * @param boolean $where If true, "WHERE " will be prepended to the return value + * @param Model $model A reference to the Model instance making the query + * @return string SQL fragment + */ + public function conditions($conditions, $quoteValues = true, $where = true, $model = null) { + $clause = $out = ''; + + if ($where) { + $clause = ' WHERE '; } -/** - * Extracts a Model.field identifier and an SQL condition operator from a string, formats - * and inserts values, and composes them into an SQL snippet. - * - * @param Model $model Model object initiating the query - * @param string $key An SQL key snippet containing a field and optional SQL operator - * @param mixed $value The value(s) to be inserted in the string - * @return string - */ - protected function _parseKey($model, $key, $value) { - $operatorMatch = '/^(((' . implode(')|(', $this->_sqlOps); - $operatorMatch .= ')\\x20?)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is'; - $bound = (strpos($key, '?') !== false || (is_array($value) && strpos($key, ':') !== false)); + if (is_array($conditions) && !empty($conditions)) { + $out = $this->conditionKeysToString($conditions, $quoteValues, $model); - if (strpos($key, ' ') === false) { - $operator = '='; + if (empty($out)) { + return $clause . ' 1 = 1'; + } + return $clause . implode(' AND ', $out); + } + if (is_bool($conditions)) { + return $clause . (int) $conditions . ' = 1'; + } + + if (empty($conditions) || trim($conditions) === '') { + return $clause . '1 = 1'; + } + $clauses = '/^WHERE\\x20|^GROUP\\x20BY\\x20|^HAVING\\x20|^ORDER\\x20BY\\x20/i'; + + if (preg_match($clauses, $conditions)) { + $clause = ''; + } + $conditions = $this->_quoteFields($conditions); + return $clause . $conditions; + } + + /** + * Creates a WHERE clause by parsing given conditions array. Used by DboSource::conditions(). + * + * @param array $conditions Array or string of conditions + * @param boolean $quoteValues If true, values should be quoted + * @param Model $model A reference to the Model instance making the query + * @return string SQL fragment + */ + public function conditionKeysToString($conditions, $quoteValues = true, $model = null) { + $out = array(); + $data = $columnType = null; + $bool = array('and', 'or', 'not', 'and not', 'or not', 'xor', '||', '&&'); + + foreach ($conditions as $key => $value) { + $join = ' AND '; + $not = null; + + if (is_array($value)) { + $valueInsert = ( + !empty($value) && + (substr_count($key, '?') === count($value) || substr_count($key, ':') === count($value)) + ); + } + + if (is_numeric($key) && empty($value)) { + continue; + } elseif (is_numeric($key) && is_string($value)) { + $out[] = $this->_quoteFields($value); + } elseif ((is_numeric($key) && is_array($value)) || in_array(strtolower(trim($key)), $bool)) { + if (in_array(strtolower(trim($key)), $bool)) { + $join = ' ' . strtoupper($key) . ' '; } else { - list($key, $operator) = explode(' ', trim($key), 2); + $key = $join; + } + $value = $this->conditionKeysToString($value, $quoteValues, $model); - if (!preg_match($operatorMatch, trim($operator)) && strpos($operator, ' ') !== false) { - $key = $key . ' ' . $operator; - $split = strrpos($key, ' '); - $operator = substr($key, $split); - $key = substr($key, 0, $split); - } + if (strpos($join, 'NOT') !== false) { + if (strtoupper(trim($key)) === 'NOT') { + $key = 'AND ' . trim($key); + } + $not = 'NOT '; } - $virtual = false; - if (is_object($model) && $model->isVirtualField($key)) { - $key = $this->_quoteFields($model->getVirtualField($key)); - $virtual = true; + if (empty($value)) { + continue; } - $type = is_object($model) ? $model->getColumnType($key) : null; - $null = $value === null || (is_array($value) && empty($value)); - - if (strtolower($operator) === 'not') { - $data = $this->conditionKeysToString( - array($operator => array($key => $value)), true, $model - ); - return $data[0]; + if (empty($value[1])) { + if ($not) { + $out[] = $not . '(' . $value[0] . ')'; + } else { + $out[] = $value[0]; + } + } else { + $out[] = '(' . $not . '(' . implode(') ' . strtoupper($key) . ' (', $value) . '))'; } - - $value = $this->value($value, $type); - - if (!$virtual && $key !== '?') { - $isKey = ( - strpos($key, '(') !== false || - strpos($key, ')') !== false || - strpos($key, '|') !== false - ); - $key = $isKey ? $this->_quoteFields($key) : $this->name($key); - } - - if ($bound) { - return String::insert($key . ' ' . trim($operator), $value); - } - - if (!preg_match($operatorMatch, trim($operator))) { - $operator .= is_array($value) ? ' IN' : ' ='; - } - $operator = trim($operator); - - if (is_array($value)) { - $value = implode(', ', $value); - - switch ($operator) { - case '=': - $operator = 'IN'; - break; - case '!=': - case '<>': - $operator = 'NOT IN'; - break; - } - $value = "({$value})"; - } elseif ($null || $value === 'NULL') { - switch ($operator) { - case '=': - $operator = 'IS'; - break; - case '!=': - case '<>': - $operator = 'IS NOT'; - break; - } - } - if ($virtual) { - return "({$key}) {$operator} {$value}"; - } - return "{$key} {$operator} {$value}"; - } - -/** - * Quotes Model.fields - * - * @param string $conditions - * @return string or false if no match - */ - protected function _quoteFields($conditions) { - $start = $end = null; - $original = $conditions; - - if (!empty($this->startQuote)) { - $start = preg_quote($this->startQuote); - } - if (!empty($this->endQuote)) { - $end = preg_quote($this->endQuote); - } - $conditions = str_replace(array($start, $end), '', $conditions); - $conditions = preg_replace_callback( - '/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_][a-z0-9\\-_]*\\.[a-z0-9_][a-z0-9_\\-]*)/i', - array(&$this, '_quoteMatchedField'), - $conditions - ); - if ($conditions !== null) { - return $conditions; - } - return $original; - } - -/** - * Auxiliary function to quote matches `Model.fields` from a preg_replace_callback call - * - * @param string $match matched string - * @return string quoted string - */ - protected function _quoteMatchedField($match) { - if (is_numeric($match[0])) { - return $match[0]; - } - return $this->name($match[0]); - } - -/** - * Returns a limit statement in the correct format for the particular database. - * - * @param integer $limit Limit of results returned - * @param integer $offset Offset from which to start results - * @return string SQL limit/offset statement - */ - public function limit($limit, $offset = null) { - if ($limit) { - $rt = ' LIMIT'; - - if ($offset) { - $rt .= sprintf(' %u,', $offset); - } - - $rt .= sprintf(' %u', $limit); - return $rt; - } - return null; - } - -/** - * Returns an ORDER BY clause as a string. - * - * @param array|string $keys Field reference, as a key (i.e. Post.title) - * @param string $direction Direction (ASC or DESC) - * @param Model $model model reference (used to look for virtual field) - * @return string ORDER BY clause - */ - public function order($keys, $direction = 'ASC', $model = null) { - if (!is_array($keys)) { - $keys = array($keys); - } - $keys = array_filter($keys); - $result = array(); - while (!empty($keys)) { - list($key, $dir) = each($keys); - array_shift($keys); - + } else { + if (is_object($value) && isset($value->type)) { + if ($value->type === 'identifier') { + $data .= $this->name($key) . ' = ' . $this->name($value->value); + } elseif ($value->type === 'expression') { if (is_numeric($key)) { - $key = $dir; - $dir = $direction; - } - - if (is_string($key) && strpos($key, ',') !== false && !preg_match('/\(.+\,.+\)/', $key)) { - $key = array_map('trim', explode(',', $key)); - } - if (is_array($key)) { - //Flatten the array - $key = array_reverse($key, true); - foreach ($key as $k => $v) { - if (is_numeric($k)) { - array_unshift($keys, $v); - } else { - $keys = array($k => $v) + $keys; - } - } - continue; - } elseif (is_object($key) && isset($key->type) && $key->type === 'expression') { - $result[] = $key->value; - continue; - } - - if (preg_match('/\\x20(ASC|DESC).*/i', $key, $_dir)) { - $dir = $_dir[0]; - $key = preg_replace('/\\x20(ASC|DESC).*/i', '', $key); - } - - $key = trim($key); - - if (is_object($model) && $model->isVirtualField($key)) { - $key = '(' . $this->_quoteFields($model->getVirtualField($key)) . ')'; - } - list($alias, $field) = pluginSplit($key); - if (is_object($model) && $alias !== $model->alias && is_object($model->{$alias}) && $model->{$alias}->isVirtualField($key)) { - $key = '(' . $this->_quoteFields($model->{$alias}->getVirtualField($key)) . ')'; - } - - if (strpos($key, '.')) { - $key = preg_replace_callback('/([a-zA-Z0-9_-]{1,})\\.([a-zA-Z0-9_-]{1,})/', array(&$this, '_quoteMatchedField'), $key); - } - if (!preg_match('/\s/', $key) && strpos($key, '.') === false) { - $key = $this->name($key); - } - $key .= ' ' . trim($dir); - $result[] = $key; - } - if (!empty($result)) { - return ' ORDER BY ' . implode(', ', $result); - } - return ''; - } - -/** - * Create a GROUP BY SQL clause - * - * @param string $group Group By Condition - * @param Model $model - * @return string string condition or null - */ - public function group($group, $model = null) { - if ($group) { - if (!is_array($group)) { - $group = array($group); - } - foreach ($group as $index => $key) { - if (is_object($model) && $model->isVirtualField($key)) { - $group[$index] = '(' . $model->getVirtualField($key) . ')'; - } - } - $group = implode(', ', $group); - return ' GROUP BY ' . $this->_quoteFields($group); - } - return null; - } - -/** - * Disconnects database, kills the connection and says the connection is closed. - * - * @return void - */ - public function close() { - $this->disconnect(); - } - -/** - * Checks if the specified table contains any record matching specified SQL - * - * @param Model $Model Model to search - * @param string $sql SQL WHERE clause (condition only, not the "WHERE" part) - * @return boolean True if the table has a matching record, else false - */ - public function hasAny(Model $Model, $sql) { - $sql = $this->conditions($sql); - $table = $this->fullTableName($Model); - $alias = $this->alias . $this->name($Model->alias); - $where = $sql ? "{$sql}" : ' WHERE 1 = 1'; - $id = $Model->escapeField(); - - $out = $this->fetchRow("SELECT COUNT({$id}) {$this->alias}count FROM {$table} {$alias}{$where}"); - - if (is_array($out)) { - return $out[0]['count']; - } - return false; - } - -/** - * Gets the length of a database-native column description, or null if no length - * - * @param string $real Real database-layer column type (i.e. "varchar(255)") - * @return mixed An integer or string representing the length of the column, or null for unknown length. - */ - public function length($real) { - if (!preg_match_all('/([\w\s]+)(?:\((\d+)(?:,(\d+))?\))?(\sunsigned)?(\szerofill)?/', $real, $result)) { - $col = str_replace(array(')', 'unsigned'), '', $real); - $limit = null; - - if (strpos($col, '(') !== false) { - list($col, $limit) = explode('(', $col); - } - if ($limit !== null) { - return intval($limit); - } - return null; - } - - $types = array( - 'int' => 1, 'tinyint' => 1, 'smallint' => 1, 'mediumint' => 1, 'integer' => 1, 'bigint' => 1 - ); - - list($real, $type, $length, $offset, $sign, $zerofill) = $result; - $typeArr = $type; - $type = $type[0]; - $length = $length[0]; - $offset = $offset[0]; - - $isFloat = in_array($type, array('dec', 'decimal', 'float', 'numeric', 'double')); - if ($isFloat && $offset) { - return $length . ',' . $offset; - } - - if (($real[0] == $type) && (count($real) === 1)) { - return null; - } - - if (isset($types[$type])) { - $length += $types[$type]; - if (!empty($sign)) { - $length--; - } - } elseif (in_array($type, array('enum', 'set'))) { - $length = 0; - foreach ($typeArr as $key => $enumValue) { - if ($key === 0) { - continue; - } - $tmpLength = strlen($enumValue); - if ($tmpLength > $length) { - $length = $tmpLength; - } - } - } - return intval($length); - } - -/** - * Translates between PHP boolean values and Database (faked) boolean values - * - * @param mixed $data Value to be translated - * @param boolean $quote - * @return string|boolean Converted boolean value - */ - public function boolean($data, $quote = false) { - if ($quote) { - return !empty($data) ? '1' : '0'; - } - return !empty($data); - } - -/** - * Inserts multiple values into a table - * - * @param string $table The table being inserted into. - * @param array $fields The array of field/column names being inserted. - * @param array $values The array of values to insert. The values should - * be an array of rows. Each row should have values keyed by the column name. - * Each row must have the values in the same order as $fields. - * @return boolean - */ - public function insertMulti($table, $fields, $values) { - $table = $this->fullTableName($table); - $holder = implode(',', array_fill(0, count($fields), '?')); - $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); - - $pdoMap = array( - 'integer' => PDO::PARAM_INT, - 'float' => PDO::PARAM_STR, - 'boolean' => PDO::PARAM_BOOL, - 'string' => PDO::PARAM_STR, - 'text' => PDO::PARAM_STR - ); - $columnMap = array(); - - $sql = "INSERT INTO {$table} ({$fields}) VALUES ({$holder})"; - $statement = $this->_connection->prepare($sql); - $this->begin(); - - foreach ($values[key($values)] as $key => $val) { - $type = $this->introspectType($val); - $columnMap[$key] = $pdoMap[$type]; - } - - foreach ($values as $value) { - $i = 1; - foreach ($value as $col => $val) { - $statement->bindValue($i, $val, $columnMap[$col]); - $i += 1; - } - $statement->execute(); - $statement->closeCursor(); - - if ($this->fullDebug) { - $this->logQuery($sql, $value); - } - } - return $this->commit(); - } - -/** - * Reset a sequence based on the MAX() value of $column. Useful - * for resetting sequences after using insertMulti(). - * - * This method should be implemented by datasources that require sequences to be used. - * - * @param string $table The name of the table to update. - * @param string $column The column to use when resetting the sequence value. - * @return boolean|void success. - */ - public function resetSequence($table, $column) { - } - -/** - * Returns an array of the indexes in given datasource name. - * - * @param string $model Name of model to inspect - * @return array Fields in table. Keys are column and unique - */ - public function index($model) { - return array(); - } - -/** - * Generate a database-native schema for the given Schema object - * - * @param CakeSchema $schema An instance of a subclass of CakeSchema - * @param string $tableName Optional. If specified only the table name given will be generated. - * Otherwise, all tables defined in the schema are generated. - * @return string - */ - public function createSchema($schema, $tableName = null) { - if (!is_a($schema, 'CakeSchema')) { - trigger_error(__d('cake_dev', 'Invalid schema object'), E_USER_WARNING); - return null; - } - $out = ''; - - foreach ($schema->tables as $curTable => $columns) { - if (!$tableName || $tableName == $curTable) { - $cols = $indexes = $tableParameters = array(); - $primary = null; - $table = $this->fullTableName($curTable); - - $primaryCount = 0; - foreach ($columns as $col) { - if (isset($col['key']) && $col['key'] === 'primary') { - $primaryCount++; - } - } - - foreach ($columns as $name => $col) { - if (is_string($col)) { - $col = array('type' => $col); - } - $isPrimary = isset($col['key']) && $col['key'] === 'primary'; - // Multi-column primary keys are not supported. - if ($isPrimary && $primaryCount > 1) { - unset($col['key']); - $isPrimary = false; - } - if ($isPrimary) { - $primary = $name; - } - if ($name !== 'indexes' && $name !== 'tableParameters') { - $col['name'] = $name; - if (!isset($col['type'])) { - $col['type'] = 'string'; - } - $cols[] = $this->buildColumn($col); - } elseif ($name === 'indexes') { - $indexes = array_merge($indexes, $this->buildIndex($col, $table)); - } elseif ($name === 'tableParameters') { - $tableParameters = array_merge($tableParameters, $this->buildTableParameters($col, $table)); - } - } - if (!isset($columns['indexes']['PRIMARY']) && !empty($primary)) { - $col = array('PRIMARY' => array('column' => $primary, 'unique' => 1)); - $indexes = array_merge($indexes, $this->buildIndex($col, $table)); - } - $columns = $cols; - $out .= $this->renderStatement('schema', compact('table', 'columns', 'indexes', 'tableParameters')) . "\n\n"; - } - } - return $out; - } - -/** - * Generate a alter syntax from CakeSchema::compare() - * - * @param mixed $compare - * @param string $table - * @return boolean - */ - public function alterSchema($compare, $table = null) { - return false; - } - -/** - * Generate a "drop table" statement for the given Schema object - * - * @param CakeSchema $schema An instance of a subclass of CakeSchema - * @param string $table Optional. If specified only the table name given will be generated. - * Otherwise, all tables defined in the schema are generated. - * @return string - */ - public function dropSchema(CakeSchema $schema, $table = null) { - $out = ''; - - if ($table && array_key_exists($table, $schema->tables)) { - return $this->_dropTable($table) . "\n"; - } elseif ($table) { - return $out; - } - - foreach (array_keys($schema->tables) as $curTable) { - $out .= $this->_dropTable($curTable) . "\n"; - } - return $out; - } - -/** - * Generate a "drop table" statement for a single table - * - * @param type $table Name of the table to drop - * @return string Drop table SQL statement - */ - protected function _dropTable($table) { - return 'DROP TABLE ' . $this->fullTableName($table) . ";"; - } - -/** - * Generate a database-native column schema string - * - * @param array $column An array structured like the following: array('name' => 'value', 'type' => 'value'[, options]), - * where options can be 'default', 'length', or 'key'. - * @return string - */ - public function buildColumn($column) { - $name = $type = null; - extract(array_merge(array('null' => true), $column)); - - if (empty($name) || empty($type)) { - trigger_error(__d('cake_dev', 'Column name or type not defined in schema'), E_USER_WARNING); - return null; - } - - if (!isset($this->columns[$type])) { - trigger_error(__d('cake_dev', 'Column type %s does not exist', $type), E_USER_WARNING); - return null; - } - - $real = $this->columns[$type]; - $out = $this->name($name) . ' ' . $real['name']; - - if (isset($column['length'])) { - $length = $column['length']; - } elseif (isset($column['limit'])) { - $length = $column['limit']; - } elseif (isset($real['length'])) { - $length = $real['length']; - } elseif (isset($real['limit'])) { - $length = $real['limit']; - } - if (isset($length)) { - $out .= '(' . $length . ')'; - } - - if (($column['type'] === 'integer' || $column['type'] === 'float') && isset($column['default']) && $column['default'] === '') { - $column['default'] = null; - } - $out = $this->_buildFieldParameters($out, $column, 'beforeDefault'); - - if (isset($column['key']) && $column['key'] === 'primary' && ($type === 'integer' || $type === 'biginteger')) { - $out .= ' ' . $this->columns['primary_key']['name']; - } elseif (isset($column['key']) && $column['key'] === 'primary') { - $out .= ' NOT NULL'; - } elseif (isset($column['default']) && isset($column['null']) && $column['null'] === false) { - $out .= ' DEFAULT ' . $this->value($column['default'], $type) . ' NOT NULL'; - } elseif (isset($column['default'])) { - $out .= ' DEFAULT ' . $this->value($column['default'], $type); - } elseif ($type !== 'timestamp' && !empty($column['null'])) { - $out .= ' DEFAULT NULL'; - } elseif ($type === 'timestamp' && !empty($column['null'])) { - $out .= ' NULL'; - } elseif (isset($column['null']) && $column['null'] === false) { - $out .= ' NOT NULL'; - } - if ($type === 'timestamp' && isset($column['default']) && strtolower($column['default']) === 'current_timestamp') { - $out = str_replace(array("'CURRENT_TIMESTAMP'", "'current_timestamp'"), 'CURRENT_TIMESTAMP', $out); - } - return $this->_buildFieldParameters($out, $column, 'afterDefault'); - } - -/** - * Build the field parameters, in a position - * - * @param string $columnString The partially built column string - * @param array $columnData The array of column data. - * @param string $position The position type to use. 'beforeDefault' or 'afterDefault' are common - * @return string a built column with the field parameters added. - */ - protected function _buildFieldParameters($columnString, $columnData, $position) { - foreach ($this->fieldParameters as $paramName => $value) { - if (isset($columnData[$paramName]) && $value['position'] == $position) { - if (isset($value['options']) && !in_array($columnData[$paramName], $value['options'])) { - continue; - } - $val = $columnData[$paramName]; - if ($value['quote']) { - $val = $this->value($val); - } - $columnString .= ' ' . $value['value'] . $value['join'] . $val; - } - } - return $columnString; - } - -/** - * Format indexes for create table. - * - * @param array $indexes - * @param string $table - * @return array - */ - public function buildIndex($indexes, $table = null) { - $join = array(); - foreach ($indexes as $name => $value) { - $out = ''; - if ($name === 'PRIMARY') { - $out .= 'PRIMARY '; - $name = null; + $data .= $value->value; } else { - if (!empty($value['unique'])) { - $out .= 'UNIQUE '; + $data .= $this->name($key) . ' = ' . $value->value; + } + } + } elseif (is_array($value) && !empty($value) && !$valueInsert) { + $keys = array_keys($value); + if ($keys === array_values($keys)) { + $count = count($value); + if ($count === 1 && !preg_match("/\s+NOT$/", $key)) { + $data = $this->_quoteFields($key) . ' = ('; + if ($quoteValues) { + if (is_object($model)) { + $columnType = $model->getColumnType($key); } - $name = $this->startQuote . $name . $this->endQuote; - } - if (is_array($value['column'])) { - $out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')'; + $data .= implode(', ', $this->value($value, $columnType)); + } + $data .= ')'; } else { - $out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')'; + $data = $this->_parseKey($model, $key, $value); } - $join[] = $out; + } else { + $ret = $this->conditionKeysToString($value, $quoteValues, $model); + if (count($ret) > 1) { + $data = '(' . implode(') AND (', $ret) . ')'; + } elseif (isset($ret[0])) { + $data = $ret[0]; + } + } + } elseif (is_numeric($key) && !empty($value)) { + $data = $this->_quoteFields($value); + } else { + $data = $this->_parseKey($model, trim($key), $value); } - return $join; + + if ($data) { + $out[] = $data; + $data = null; + } + } + } + return $out; + } + + /** + * Extracts a Model.field identifier and an SQL condition operator from a string, formats + * and inserts values, and composes them into an SQL snippet. + * + * @param Model $model Model object initiating the query + * @param string $key An SQL key snippet containing a field and optional SQL operator + * @param mixed $value The value(s) to be inserted in the string + * @return string + */ + protected function _parseKey($model, $key, $value) { + $operatorMatch = '/^(((' . implode(')|(', $this->_sqlOps); + $operatorMatch .= ')\\x20?)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is'; + $bound = (strpos($key, '?') !== false || (is_array($value) && strpos($key, ':') !== false)); + + if (strpos($key, ' ') === false) { + $operator = '='; + } else { + list($key, $operator) = explode(' ', trim($key), 2); + + if (!preg_match($operatorMatch, trim($operator)) && strpos($operator, ' ') !== false) { + $key = $key . ' ' . $operator; + $split = strrpos($key, ' '); + $operator = substr($key, $split); + $key = substr($key, 0, $split); + } } -/** - * Read additional table parameters - * - * @param string $name - * @return array - */ - public function readTableParameters($name) { - $parameters = array(); - if (method_exists($this, 'listDetailedSources')) { - $currentTableDetails = $this->listDetailedSources($name); - foreach ($this->tableParameters as $paramName => $parameter) { - if (!empty($parameter['column']) && !empty($currentTableDetails[$parameter['column']])) { - $parameters[$paramName] = $currentTableDetails[$parameter['column']]; - } - } - } - return $parameters; + $virtual = false; + if (is_object($model) && $model->isVirtualField($key)) { + $key = $this->_quoteFields($model->getVirtualField($key)); + $virtual = true; } -/** - * Format parameters for create table - * - * @param array $parameters - * @param string $table - * @return array - */ - public function buildTableParameters($parameters, $table = null) { - $result = array(); - foreach ($parameters as $name => $value) { - if (isset($this->tableParameters[$name])) { - if ($this->tableParameters[$name]['quote']) { - $value = $this->value($value); - } - $result[] = $this->tableParameters[$name]['value'] . $this->tableParameters[$name]['join'] . $value; - } - } - return $result; + $type = is_object($model) ? $model->getColumnType($key) : null; + $null = $value === null || (is_array($value) && empty($value)); + + if (strtolower($operator) === 'not') { + $data = $this->conditionKeysToString( + array($operator => array($key => $value)), true, $model + ); + return $data[0]; } -/** - * Guesses the data type of an array - * - * @param string $value - * @return void - */ - public function introspectType($value) { - if (!is_array($value)) { - if (is_bool($value)) { - return 'boolean'; - } - if (is_float($value) && floatval($value) === $value) { - return 'float'; - } - if (is_int($value) && intval($value) === $value) { - return 'integer'; - } - if (is_string($value) && strlen($value) > 255) { - return 'text'; - } - return 'string'; - } + $value = $this->value($value, $type); - $isAllFloat = $isAllInt = true; - $containsFloat = $containsInt = $containsString = false; - foreach ($value as $valElement) { - $valElement = trim($valElement); - if (!is_float($valElement) && !preg_match('/^[\d]+\.[\d]+$/', $valElement)) { - $isAllFloat = false; - } else { - $containsFloat = true; - continue; - } - if (!is_int($valElement) && !preg_match('/^[\d]+$/', $valElement)) { - $isAllInt = false; - } else { - $containsInt = true; - continue; - } - $containsString = true; - } - - if ($isAllFloat) { - return 'float'; - } - if ($isAllInt) { - return 'integer'; - } - - if ($containsInt && !$containsString) { - return 'integer'; - } - return 'string'; + if (!$virtual && $key !== '?') { + $isKey = ( + strpos($key, '(') !== false || + strpos($key, ')') !== false || + strpos($key, '|') !== false + ); + $key = $isKey ? $this->_quoteFields($key) : $this->name($key); } -/** - * Writes a new key for the in memory sql query cache - * - * @param string $sql SQL query - * @param mixed $data result of $sql query - * @param array $params query params bound as values - * @return void - */ - protected function _writeQueryCache($sql, $data, $params = array()) { - if (preg_match('/^\s*select/i', $sql)) { - $this->_queryCache[$sql][serialize($params)] = $data; - } + if ($bound) { + return String::insert($key . ' ' . trim($operator), $value); } -/** - * Returns the result for a sql query if it is already cached - * - * @param string $sql SQL query - * @param array $params query params bound as values - * @return mixed results for query if it is cached, false otherwise - */ - public function getQueryCache($sql, $params = array()) { - if (isset($this->_queryCache[$sql]) && preg_match('/^\s*select/i', $sql)) { - $serialized = serialize($params); - if (isset($this->_queryCache[$sql][$serialized])) { - return $this->_queryCache[$sql][$serialized]; + if (!preg_match($operatorMatch, trim($operator))) { + $operator .= is_array($value) ? ' IN' : ' ='; + } + $operator = trim($operator); + + if (is_array($value)) { + $value = implode(', ', $value); + + switch ($operator) { + case '=': + $operator = 'IN'; + break; + case '!=': + case '<>': + $operator = 'NOT IN'; + break; + } + $value = "({$value})"; + } elseif ($null || $value === 'NULL') { + switch ($operator) { + case '=': + $operator = 'IS'; + break; + case '!=': + case '<>': + $operator = 'IS NOT'; + break; + } + } + if ($virtual) { + return "({$key}) {$operator} {$value}"; + } + return "{$key} {$operator} {$value}"; + } + + /** + * Quotes Model.fields + * + * @param string $conditions + * @return string or false if no match + */ + protected function _quoteFields($conditions) { + $start = $end = null; + $original = $conditions; + + if (!empty($this->startQuote)) { + $start = preg_quote($this->startQuote); + } + if (!empty($this->endQuote)) { + $end = preg_quote($this->endQuote); + } + $conditions = str_replace(array($start, $end), '', $conditions); + $conditions = preg_replace_callback( + '/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_][a-z0-9\\-_]*\\.[a-z0-9_][a-z0-9_\\-]*)/i', array(&$this, '_quoteMatchedField'), $conditions + ); + if ($conditions !== null) { + return $conditions; + } + return $original; + } + + /** + * Auxiliary function to quote matches `Model.fields` from a preg_replace_callback call + * + * @param string $match matched string + * @return string quoted string + */ + protected function _quoteMatchedField($match) { + if (is_numeric($match[0])) { + return $match[0]; + } + return $this->name($match[0]); + } + + /** + * Returns a limit statement in the correct format for the particular database. + * + * @param integer $limit Limit of results returned + * @param integer $offset Offset from which to start results + * @return string SQL limit/offset statement + */ + public function limit($limit, $offset = null) { + if ($limit) { + $rt = ' LIMIT'; + + if ($offset) { + $rt .= sprintf(' %u,', $offset); + } + + $rt .= sprintf(' %u', $limit); + return $rt; + } + return null; + } + + /** + * Returns an ORDER BY clause as a string. + * + * @param array|string $keys Field reference, as a key (i.e. Post.title) + * @param string $direction Direction (ASC or DESC) + * @param Model $model model reference (used to look for virtual field) + * @return string ORDER BY clause + */ + public function order($keys, $direction = 'ASC', $model = null) { + if (!is_array($keys)) { + $keys = array($keys); + } + $keys = array_filter($keys); + $result = array(); + while (!empty($keys)) { + list($key, $dir) = each($keys); + array_shift($keys); + + if (is_numeric($key)) { + $key = $dir; + $dir = $direction; + } + + if (is_string($key) && strpos($key, ',') !== false && !preg_match('/\(.+\,.+\)/', $key)) { + $key = array_map('trim', explode(',', $key)); + } + if (is_array($key)) { + //Flatten the array + $key = array_reverse($key, true); + foreach ($key as $k => $v) { + if (is_numeric($k)) { + array_unshift($keys, $v); + } else { + $keys = array($k => $v) + $keys; + } + } + continue; + } elseif (is_object($key) && isset($key->type) && $key->type === 'expression') { + $result[] = $key->value; + continue; + } + + if (preg_match('/\\x20(ASC|DESC).*/i', $key, $_dir)) { + $dir = $_dir[0]; + $key = preg_replace('/\\x20(ASC|DESC).*/i', '', $key); + } + + $key = trim($key); + + if (is_object($model) && $model->isVirtualField($key)) { + $key = '(' . $this->_quoteFields($model->getVirtualField($key)) . ')'; + } + list($alias, $field) = pluginSplit($key); + if (is_object($model) && $alias !== $model->alias && is_object($model->{$alias}) && $model->{$alias}->isVirtualField($key)) { + $key = '(' . $this->_quoteFields($model->{$alias}->getVirtualField($key)) . ')'; + } + + if (strpos($key, '.')) { + $key = preg_replace_callback('/([a-zA-Z0-9_-]{1,})\\.([a-zA-Z0-9_-]{1,})/', array(&$this, '_quoteMatchedField'), $key); + } + if (!preg_match('/\s/', $key) && strpos($key, '.') === false) { + $key = $this->name($key); + } + $key .= ' ' . trim($dir); + $result[] = $key; + } + if (!empty($result)) { + return ' ORDER BY ' . implode(', ', $result); + } + return ''; + } + + /** + * Create a GROUP BY SQL clause + * + * @param string $group Group By Condition + * @param Model $model + * @return string string condition or null + */ + public function group($group, $model = null) { + if ($group) { + if (!is_array($group)) { + $group = array($group); + } + foreach ($group as $index => $key) { + if (is_object($model) && $model->isVirtualField($key)) { + $group[$index] = '(' . $model->getVirtualField($key) . ')'; + } + } + $group = implode(', ', $group); + return ' GROUP BY ' . $this->_quoteFields($group); + } + return null; + } + + /** + * Disconnects database, kills the connection and says the connection is closed. + * + * @return void + */ + public function close() { + $this->disconnect(); + } + + /** + * Checks if the specified table contains any record matching specified SQL + * + * @param Model $Model Model to search + * @param string $sql SQL WHERE clause (condition only, not the "WHERE" part) + * @return boolean True if the table has a matching record, else false + */ + public function hasAny(Model $Model, $sql) { + $sql = $this->conditions($sql); + $table = $this->fullTableName($Model); + $alias = $this->alias . $this->name($Model->alias); + $where = $sql ? "{$sql}" : ' WHERE 1 = 1'; + $id = $Model->escapeField(); + + $out = $this->fetchRow("SELECT COUNT({$id}) {$this->alias}count FROM {$table} {$alias}{$where}"); + + if (is_array($out)) { + return $out[0]['count']; + } + return false; + } + + /** + * Gets the length of a database-native column description, or null if no length + * + * @param string $real Real database-layer column type (i.e. "varchar(255)") + * @return mixed An integer or string representing the length of the column, or null for unknown length. + */ + public function length($real) { + if (!preg_match_all('/([\w\s]+)(?:\((\d+)(?:,(\d+))?\))?(\sunsigned)?(\szerofill)?/', $real, $result)) { + $col = str_replace(array(')', 'unsigned'), '', $real); + $limit = null; + + if (strpos($col, '(') !== false) { + list($col, $limit) = explode('(', $col); + } + if ($limit !== null) { + return intval($limit); + } + return null; + } + + $types = array( + 'int' => 1, 'tinyint' => 1, 'smallint' => 1, 'mediumint' => 1, 'integer' => 1, 'bigint' => 1 + ); + + list($real, $type, $length, $offset, $sign, $zerofill) = $result; + $typeArr = $type; + $type = $type[0]; + $length = $length[0]; + $offset = $offset[0]; + + $isFloat = in_array($type, array('dec', 'decimal', 'float', 'numeric', 'double')); + if ($isFloat && $offset) { + return $length . ',' . $offset; + } + + if (($real[0] == $type) && (count($real) === 1)) { + return null; + } + + if (isset($types[$type])) { + $length += $types[$type]; + if (!empty($sign)) { + $length--; + } + } elseif (in_array($type, array('enum', 'set'))) { + $length = 0; + foreach ($typeArr as $key => $enumValue) { + if ($key === 0) { + continue; + } + $tmpLength = strlen($enumValue); + if ($tmpLength > $length) { + $length = $tmpLength; + } + } + } + return intval($length); + } + + /** + * Translates between PHP boolean values and Database (faked) boolean values + * + * @param mixed $data Value to be translated + * @param boolean $quote + * @return string|boolean Converted boolean value + */ + public function boolean($data, $quote = false) { + if ($quote) { + return !empty($data) ? '1' : '0'; + } + return !empty($data); + } + + /** + * Inserts multiple values into a table + * + * @param string $table The table being inserted into. + * @param array $fields The array of field/column names being inserted. + * @param array $values The array of values to insert. The values should + * be an array of rows. Each row should have values keyed by the column name. + * Each row must have the values in the same order as $fields. + * @return boolean + */ + public function insertMulti($table, $fields, $values) { + $table = $this->fullTableName($table); + $holder = implode(',', array_fill(0, count($fields), '?')); + $fields = implode(', ', array_map(array(&$this, 'name'), $fields)); + + $pdoMap = array( + 'integer' => PDO::PARAM_INT, + 'float' => PDO::PARAM_STR, + 'boolean' => PDO::PARAM_BOOL, + 'string' => PDO::PARAM_STR, + 'text' => PDO::PARAM_STR + ); + $columnMap = array(); + + $sql = "INSERT INTO {$table} ({$fields}) VALUES ({$holder})"; + $statement = $this->_connection->prepare($sql); + $this->begin(); + + foreach ($values[key($values)] as $key => $val) { + $type = $this->introspectType($val); + $columnMap[$key] = $pdoMap[$type]; + } + + foreach ($values as $value) { + $i = 1; + foreach ($value as $col => $val) { + $statement->bindValue($i, $val, $columnMap[$col]); + $i += 1; + } + $statement->execute(); + $statement->closeCursor(); + + if ($this->fullDebug) { + $this->logQuery($sql, $value); + } + } + return $this->commit(); + } + + /** + * Reset a sequence based on the MAX() value of $column. Useful + * for resetting sequences after using insertMulti(). + * + * This method should be implemented by datasources that require sequences to be used. + * + * @param string $table The name of the table to update. + * @param string $column The column to use when resetting the sequence value. + * @return boolean|void success. + */ + public function resetSequence($table, $column) { + + } + + /** + * Returns an array of the indexes in given datasource name. + * + * @param string $model Name of model to inspect + * @return array Fields in table. Keys are column and unique + */ + public function index($model) { + return array(); + } + + /** + * Generate a database-native schema for the given Schema object + * + * @param CakeSchema $schema An instance of a subclass of CakeSchema + * @param string $tableName Optional. If specified only the table name given will be generated. + * Otherwise, all tables defined in the schema are generated. + * @return string + */ + public function createSchema($schema, $tableName = null) { + if (!is_a($schema, 'CakeSchema')) { + trigger_error(__d('cake_dev', 'Invalid schema object'), E_USER_WARNING); + return null; + } + $out = ''; + + foreach ($schema->tables as $curTable => $columns) { + if (!$tableName || $tableName == $curTable) { + $cols = $indexes = $tableParameters = array(); + $primary = null; + $table = $this->fullTableName($curTable); + + $primaryCount = 0; + foreach ($columns as $col) { + if (isset($col['key']) && $col['key'] === 'primary') { + $primaryCount++; + } + } + + foreach ($columns as $name => $col) { + if (is_string($col)) { + $col = array('type' => $col); + } + $isPrimary = isset($col['key']) && $col['key'] === 'primary'; + // Multi-column primary keys are not supported. + if ($isPrimary && $primaryCount > 1) { + unset($col['key']); + $isPrimary = false; + } + if ($isPrimary) { + $primary = $name; + } + if ($name !== 'indexes' && $name !== 'tableParameters') { + $col['name'] = $name; + if (!isset($col['type'])) { + $col['type'] = 'string'; } + $cols[] = $this->buildColumn($col); + } elseif ($name === 'indexes') { + $indexes = array_merge($indexes, $this->buildIndex($col, $table)); + } elseif ($name === 'tableParameters') { + $tableParameters = array_merge($tableParameters, $this->buildTableParameters($col, $table)); + } } - return false; + if (!isset($columns['indexes']['PRIMARY']) && !empty($primary)) { + $col = array('PRIMARY' => array('column' => $primary, 'unique' => 1)); + $indexes = array_merge($indexes, $this->buildIndex($col, $table)); + } + $columns = $cols; + $out .= $this->renderStatement('schema', compact('table', 'columns', 'indexes', 'tableParameters')) . "\n\n"; + } + } + return $out; + } + + /** + * Generate a alter syntax from CakeSchema::compare() + * + * @param mixed $compare + * @param string $table + * @return boolean + */ + public function alterSchema($compare, $table = null) { + return false; + } + + /** + * Generate a "drop table" statement for the given Schema object + * + * @param CakeSchema $schema An instance of a subclass of CakeSchema + * @param string $table Optional. If specified only the table name given will be generated. + * Otherwise, all tables defined in the schema are generated. + * @return string + */ + public function dropSchema(CakeSchema $schema, $table = null) { + $out = ''; + + if ($table && array_key_exists($table, $schema->tables)) { + return $this->_dropTable($table) . "\n"; + } elseif ($table) { + return $out; } -/** - * Used for storing in cache the results of the in-memory methodCache - * - */ - public function __destruct() { - if ($this->_methodCacheChange) { - Cache::write('method_cache', self::$methodCache, '_cake_core_'); - } + foreach (array_keys($schema->tables) as $curTable) { + $out .= $this->_dropTable($curTable) . "\n"; } + return $out; + } + + /** + * Generate a "drop table" statement for a single table + * + * @param type $table Name of the table to drop + * @return string Drop table SQL statement + */ + protected function _dropTable($table) { + return 'DROP TABLE ' . $this->fullTableName($table) . ";"; + } + + /** + * Generate a database-native column schema string + * + * @param array $column An array structured like the following: array('name' => 'value', 'type' => 'value'[, options]), + * where options can be 'default', 'length', or 'key'. + * @return string + */ + public function buildColumn($column) { + $name = $type = null; + extract(array_merge(array('null' => true), $column)); + + if (empty($name) || empty($type)) { + trigger_error(__d('cake_dev', 'Column name or type not defined in schema'), E_USER_WARNING); + return null; + } + + if (!isset($this->columns[$type])) { + trigger_error(__d('cake_dev', 'Column type %s does not exist', $type), E_USER_WARNING); + return null; + } + + $real = $this->columns[$type]; + $out = $this->name($name) . ' ' . $real['name']; + + if (isset($column['length'])) { + $length = $column['length']; + } elseif (isset($column['limit'])) { + $length = $column['limit']; + } elseif (isset($real['length'])) { + $length = $real['length']; + } elseif (isset($real['limit'])) { + $length = $real['limit']; + } + if (isset($length)) { + $out .= '(' . $length . ')'; + } + + if (($column['type'] === 'integer' || $column['type'] === 'float') && isset($column['default']) && $column['default'] === '') { + $column['default'] = null; + } + $out = $this->_buildFieldParameters($out, $column, 'beforeDefault'); + + if (isset($column['key']) && $column['key'] === 'primary' && ($type === 'integer' || $type === 'biginteger')) { + $out .= ' ' . $this->columns['primary_key']['name']; + } elseif (isset($column['key']) && $column['key'] === 'primary') { + $out .= ' NOT NULL'; + } elseif (isset($column['default']) && isset($column['null']) && $column['null'] === false) { + $out .= ' DEFAULT ' . $this->value($column['default'], $type) . ' NOT NULL'; + } elseif (isset($column['default'])) { + $out .= ' DEFAULT ' . $this->value($column['default'], $type); + } elseif ($type !== 'timestamp' && !empty($column['null'])) { + $out .= ' DEFAULT NULL'; + } elseif ($type === 'timestamp' && !empty($column['null'])) { + $out .= ' NULL'; + } elseif (isset($column['null']) && $column['null'] === false) { + $out .= ' NOT NULL'; + } + if ($type === 'timestamp' && isset($column['default']) && strtolower($column['default']) === 'current_timestamp') { + $out = str_replace(array("'CURRENT_TIMESTAMP'", "'current_timestamp'"), 'CURRENT_TIMESTAMP', $out); + } + return $this->_buildFieldParameters($out, $column, 'afterDefault'); + } + + /** + * Build the field parameters, in a position + * + * @param string $columnString The partially built column string + * @param array $columnData The array of column data. + * @param string $position The position type to use. 'beforeDefault' or 'afterDefault' are common + * @return string a built column with the field parameters added. + */ + protected function _buildFieldParameters($columnString, $columnData, $position) { + foreach ($this->fieldParameters as $paramName => $value) { + if (isset($columnData[$paramName]) && $value['position'] == $position) { + if (isset($value['options']) && !in_array($columnData[$paramName], $value['options'])) { + continue; + } + $val = $columnData[$paramName]; + if ($value['quote']) { + $val = $this->value($val); + } + $columnString .= ' ' . $value['value'] . $value['join'] . $val; + } + } + return $columnString; + } + + /** + * Format indexes for create table. + * + * @param array $indexes + * @param string $table + * @return array + */ + public function buildIndex($indexes, $table = null) { + $join = array(); + foreach ($indexes as $name => $value) { + $out = ''; + if ($name === 'PRIMARY') { + $out .= 'PRIMARY '; + $name = null; + } else { + if (!empty($value['unique'])) { + $out .= 'UNIQUE '; + } + $name = $this->startQuote . $name . $this->endQuote; + } + if (is_array($value['column'])) { + $out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')'; + } else { + $out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')'; + } + $join[] = $out; + } + return $join; + } + + /** + * Read additional table parameters + * + * @param string $name + * @return array + */ + public function readTableParameters($name) { + $parameters = array(); + if (method_exists($this, 'listDetailedSources')) { + $currentTableDetails = $this->listDetailedSources($name); + foreach ($this->tableParameters as $paramName => $parameter) { + if (!empty($parameter['column']) && !empty($currentTableDetails[$parameter['column']])) { + $parameters[$paramName] = $currentTableDetails[$parameter['column']]; + } + } + } + return $parameters; + } + + /** + * Format parameters for create table + * + * @param array $parameters + * @param string $table + * @return array + */ + public function buildTableParameters($parameters, $table = null) { + $result = array(); + foreach ($parameters as $name => $value) { + if (isset($this->tableParameters[$name])) { + if ($this->tableParameters[$name]['quote']) { + $value = $this->value($value); + } + $result[] = $this->tableParameters[$name]['value'] . $this->tableParameters[$name]['join'] . $value; + } + } + return $result; + } + + /** + * Guesses the data type of an array + * + * @param string $value + * @return void + */ + public function introspectType($value) { + if (!is_array($value)) { + if (is_bool($value)) { + return 'boolean'; + } + if (is_float($value) && floatval($value) === $value) { + return 'float'; + } + if (is_int($value) && intval($value) === $value) { + return 'integer'; + } + if (is_string($value) && strlen($value) > 255) { + return 'text'; + } + return 'string'; + } + + $isAllFloat = $isAllInt = true; + $containsFloat = $containsInt = $containsString = false; + foreach ($value as $valElement) { + $valElement = trim($valElement); + if (!is_float($valElement) && !preg_match('/^[\d]+\.[\d]+$/', $valElement)) { + $isAllFloat = false; + } else { + $containsFloat = true; + continue; + } + if (!is_int($valElement) && !preg_match('/^[\d]+$/', $valElement)) { + $isAllInt = false; + } else { + $containsInt = true; + continue; + } + $containsString = true; + } + + if ($isAllFloat) { + return 'float'; + } + if ($isAllInt) { + return 'integer'; + } + + if ($containsInt && !$containsString) { + return 'integer'; + } + return 'string'; + } + + /** + * Writes a new key for the in memory sql query cache + * + * @param string $sql SQL query + * @param mixed $data result of $sql query + * @param array $params query params bound as values + * @return void + */ + protected function _writeQueryCache($sql, $data, $params = array()) { + if (preg_match('/^\s*select/i', $sql)) { + $this->_queryCache[$sql][serialize($params)] = $data; + } + } + + /** + * Returns the result for a sql query if it is already cached + * + * @param string $sql SQL query + * @param array $params query params bound as values + * @return mixed results for query if it is cached, false otherwise + */ + public function getQueryCache($sql, $params = array()) { + if (isset($this->_queryCache[$sql]) && preg_match('/^\s*select/i', $sql)) { + $serialized = serialize($params); + if (isset($this->_queryCache[$sql][$serialized])) { + return $this->_queryCache[$sql][$serialized]; + } + } + return false; + } + + /** + * Used for storing in cache the results of the in-memory methodCache + * + */ + public function __destruct() { + if ($this->_methodCacheChange) { + Cache::write('method_cache', self::$methodCache, '_cake_core_'); + } + } } diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 807fde84a..6078f1df8 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -1,4 +1,5 @@ loadFixtures('User'); - $TestModel = new User(); + /** + * testExists function + * @return void + */ + public function testExists() { + $this->loadFixtures('User'); + $TestModel = new User(); - $this->assertTrue($TestModel->exists(1)); + $this->assertTrue($TestModel->exists(1)); - $TestModel->id = 2; - $this->assertTrue($TestModel->exists()); + $TestModel->id = 2; + $this->assertTrue($TestModel->exists()); - $TestModel->delete(); - $this->assertFalse($TestModel->exists()); + $TestModel->delete(); + $this->assertFalse($TestModel->exists()); - $this->assertFalse($TestModel->exists(2)); - } + $this->assertFalse($TestModel->exists(2)); + } -/** - * testFetchingNonUniqueFKJoinTableRecords() - * - * Tests if the results are properly returned in the case there are non-unique FK's - * in the join table but another fields value is different. For example: - * something_id | something_else_id | doomed = 1 - * something_id | something_else_id | doomed = 0 - * Should return both records and not just one. - * - * @return void - */ - public function testFetchingNonUniqueFKJoinTableRecords() { - $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); - $Something = new Something(); + /** + * testFetchingNonUniqueFKJoinTableRecords() + * + * Tests if the results are properly returned in the case there are non-unique FK's + * in the join table but another fields value is different. For example: + * something_id | something_else_id | doomed = 1 + * something_id | something_else_id | doomed = 0 + * Should return both records and not just one. + * + * @return void + */ + public function testFetchingNonUniqueFKJoinTableRecords() { + $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); + $Something = new Something(); - $joinThingData = array( - 'JoinThing' => array( - 'something_id' => 1, - 'something_else_id' => 2, - 'doomed' => '0', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ); + $joinThingData = array( + 'JoinThing' => array( + 'something_id' => 1, + 'something_else_id' => 2, + 'doomed' => '0', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ); - $Something->JoinThing->create($joinThingData); - $Something->JoinThing->save(); + $Something->JoinThing->create($joinThingData); + $Something->JoinThing->save(); - $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); + $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); - $this->assertEquals(true, $result[0]['JoinThing']['doomed']); - $this->assertEquals(false, $result[1]['JoinThing']['doomed']); + $this->assertEquals(true, $result[0]['JoinThing']['doomed']); + $this->assertEquals(false, $result[1]['JoinThing']['doomed']); - $result = $Something->find('first'); + $result = $Something->find('first'); - $this->assertEquals(2, count($result['SomethingElse'])); + $this->assertEquals(2, count($result['SomethingElse'])); - $doomed = Hash::extract($result['SomethingElse'], '{n}.JoinThing.doomed'); - $this->assertTrue(in_array(true, $doomed)); - $this->assertTrue(in_array(false, $doomed)); - } + $doomed = Hash::extract($result['SomethingElse'], '{n}.JoinThing.doomed'); + $this->assertTrue(in_array(true, $doomed)); + $this->assertTrue(in_array(false, $doomed)); + } -/** - * testGroupBy method - * - * These tests will never pass with Postgres or Oracle as all fields in a select must be - * part of an aggregate function or in the GROUP BY statement. - * - * @return void - */ - public function testGroupBy() { - $isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver; - $message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.'; + /** + * testGroupBy method + * + * These tests will never pass with Postgres or Oracle as all fields in a select must be + * part of an aggregate function or in the GROUP BY statement. + * + * @return void + */ + public function testGroupBy() { + $isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver; + $message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.'; - $this->skipIf($isStrictGroupBy, $message); + $this->skipIf($isStrictGroupBy, $message); - $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); - $Thread = new Thread(); - $Product = new Product(); + $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); + $Thread = new Thread(); + $Product = new Product(); - $result = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'order' => 'Thread.id ASC' + $result = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'order' => 'Thread.id ASC' )); - $expected = array( - array( - 'Thread' => array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1' - ))), - array( - 'Thread' => array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1' - ), - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2' - ), - 'Message' => array( - array( - 'id' => 3, - 'thread_id' => 3, - 'name' => 'Thread 3, Message 1' + $expected = array( + array( + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' + ))), + array( + 'Thread' => array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ), + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1' )))); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'fields' => array('Thread.project_id', 'COUNT(*) AS total') + $rows = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total') )); - $result = array(); - foreach ($rows as $row) { - $result[$row['Thread']['project_id']] = $row[0]['total']; - } - $expected = array( - 1 => 2, - 2 => 1 - ); - $this->assertEquals($expected, $result); + $result = array(); + foreach ($rows as $row) { + $result[$row['Thread']['project_id']] = $row[0]['total']; + } + $expected = array( + 1 => 2, + 2 => 1 + ); + $this->assertEquals($expected, $result); - $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), - 'order' => 'Thread.project_id' + $rows = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), + 'order' => 'Thread.project_id' )); - $result = array(); - foreach ($rows as $row) { - $result[$row['Thread']['project_id']] = $row[0]['total']; - } - $expected = array( - 1 => 2, - 2 => 1 - ); - $this->assertEquals($expected, $result); + $result = array(); + foreach ($rows as $row) { + $result[$row['Thread']['project_id']] = $row[0]['total']; + } + $expected = array( + 1 => 2, + 2 => 1 + ); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'Thread.project_id' + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id' )); - $expected = array( - array( - 'Thread' => array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1' + $expected = array( + array( + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' )))); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'Thread.project_id, Project.id' + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id, Project.id' )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'project_id' + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'project_id' )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('project_id') + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id') )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('project_id', 'Project.id') + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id', 'Project.id') )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('Thread.project_id', 'Project.id') + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('Thread.project_id', 'Project.id') )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $expected = array( - array('Product' => array('type' => 'Clothing'), array('price' => 32)), - array('Product' => array('type' => 'Food'), array('price' => 9)), - array('Product' => array('type' => 'Music'), array('price' => 4)), - array('Product' => array('type' => 'Toy'), array('price' => 3)) - ); - $result = $Product->find('all', array( - 'fields' => array('Product.type', 'MIN(Product.price) as price'), - 'group' => 'Product.type', - 'order' => 'Product.type ASC' - )); - $this->assertEquals($expected, $result); + $expected = array( + array('Product' => array('type' => 'Clothing'), array('price' => 32)), + array('Product' => array('type' => 'Food'), array('price' => 9)), + array('Product' => array('type' => 'Music'), array('price' => 4)), + array('Product' => array('type' => 'Toy'), array('price' => 3)) + ); + $result = $Product->find('all', array( + 'fields' => array('Product.type', 'MIN(Product.price) as price'), + 'group' => 'Product.type', + 'order' => 'Product.type ASC' + )); + $this->assertEquals($expected, $result); - $result = $Product->find('all', array( - 'fields' => array('Product.type', 'MIN(Product.price) as price'), - 'group' => array('Product.type'), - 'order' => 'Product.type ASC')); - $this->assertEquals($expected, $result); + $result = $Product->find('all', array( + 'fields' => array('Product.type', 'MIN(Product.price) as price'), + 'group' => array('Product.type'), + 'order' => 'Product.type ASC')); + $this->assertEquals($expected, $result); + } + + /** + * testOldQuery method + * + * @return void + */ + public function testOldQuery() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); + $Article = new Article(); + + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; + + $results = $Article->query($query); + $this->assertTrue(is_array($results)); + $this->assertEquals(2, count($results)); + + $query = 'SELECT title, body FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; + + $results = $Article->query($query, false); + $this->assertFalse($this->db->getQueryCache($query)); + $this->assertTrue(is_array($results)); + + $query = 'SELECT title, id FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ' . $this->db->value('Y'); + + $results = $Article->query($query, true); + $result = $this->db->getQueryCache($query); + $this->assertFalse(empty($result)); + $this->assertTrue(is_array($results)); + } + + /** + * testPreparedQuery method + * + * @return void + */ + public function testPreparedQuery() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $Article = new Article(); + + $query = 'SELECT title, published FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; + + $params = array(1, 'Y'); + $result = $Article->query($query, $params); + $expected = array( + '0' => array( + $this->db->fullTableName('articles', false, false) => array( + 'title' => 'First Article', 'published' => 'Y') + )); + + if (isset($result[0][0])) { + $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false, false)]; + unset($expected[0][$this->db->fullTableName('articles', false, false)]); } -/** - * testOldQuery method - * - * @return void - */ - public function testOldQuery() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); - $Article = new Article(); + $this->assertEquals($expected, $result); + $result = $this->db->getQueryCache($query, $params); + $this->assertFalse(empty($result)); - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; + $query = 'SELECT id, created FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; - $results = $Article->query($query); - $this->assertTrue(is_array($results)); - $this->assertEquals(2, count($results)); + $params = array('First Article'); + $result = $Article->query($query, $params, false); + $this->assertTrue(is_array($result)); + $this->assertTrue( + isset($result[0][$this->db->fullTableName('articles', false, false)]) || + isset($result[0][0]) + ); + $result = $this->db->getQueryCache($query, $params); + $this->assertTrue(empty($result)); - $query = 'SELECT title, body FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; - $results = $Article->query($query, false); - $this->assertFalse($this->db->getQueryCache($query)); - $this->assertTrue(is_array($results)); + $params = array('%First%'); + $result = $Article->query($query, $params); + $this->assertTrue(is_array($result)); + $this->assertTrue( + isset($result[0][$this->db->fullTableName('articles', false, false)]['title']) || + isset($result[0][0]['title']) + ); - $query = 'SELECT title, id FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.published = ' . $this->db->value('Y'); + //related to ticket #5035 + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; + $params = array('First? Article', 'Y'); + $Article->query($query, $params); - $results = $Article->query($query, true); - $result = $this->db->getQueryCache($query); - $this->assertFalse(empty($result)); - $this->assertTrue(is_array($results)); - } + $result = $this->db->getQueryCache($query, $params); + $this->assertFalse($result === false); + } -/** - * testPreparedQuery method - * - * @return void - */ - public function testPreparedQuery() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $Article = new Article(); + /** + * testParameterMismatch method + * + * @expectedException PDOException + * @return void + */ + public function testParameterMismatch() { + $this->skipIf($this->db instanceof Sqlite, 'Sqlite does not accept real prepared statements, no way to check this'); + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $Article = new Article(); - $query = 'SELECT title, published FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; + $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; + $params = array('Y'); - $params = array(1, 'Y'); - $result = $Article->query($query, $params); - $expected = array( - '0' => array( - $this->db->fullTableName('articles', false, false) => array( - 'title' => 'First Article', 'published' => 'Y') - )); + $Article->query($query, $params); + } - if (isset($result[0][0])) { - $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false, false)]; - unset($expected[0][$this->db->fullTableName('articles', false, false)]); - } + /** + * testVeryStrangeUseCase method + * + * @expectedException PDOException + * @return void + */ + public function testVeryStrangeUseCase() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $Article = new Article(); - $this->assertEquals($expected, $result); - $result = $this->db->getQueryCache($query, $params); - $this->assertFalse(empty($result)); + $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; + $param = array( + $this->db->fullTableName('articles'), + $this->db->fullTableName('articles') . '.user_id', '3', + $this->db->fullTableName('articles') . '.published', 'Y' + ); - $query = 'SELECT id, created FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; + $Article->query($query, $param); + } - $params = array('First Article'); - $result = $Article->query($query, $params, false); - $this->assertTrue(is_array($result)); - $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false, false)]) || - isset($result[0][0]) - ); - $result = $this->db->getQueryCache($query, $params); - $this->assertTrue(empty($result)); + /** + * testRecursiveUnbind method + * + * @return void + */ + public function testRecursiveUnbind() { + $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; + $this->loadFixtures('Apple', 'Sample'); + $TestModel = new Apple(); + $TestModel->recursive = 2; - $params = array('%First%'); - $result = $Article->query($query, $params); - $this->assertTrue(is_array($result)); - $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false, false)]['title']) || - isset($result[0][0]['title']) - ); - - //related to ticket #5035 - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; - $params = array('First? Article', 'Y'); - $Article->query($query, $params); - - $result = $this->db->getQueryCache($query, $params); - $this->assertFalse($result === false); - } - -/** - * testParameterMismatch method - * - * @expectedException PDOException - * @return void - */ - public function testParameterMismatch() { - $this->skipIf($this->db instanceof Sqlite, 'Sqlite does not accept real prepared statements, no way to check this'); - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $Article = new Article(); - - $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; - $params = array('Y'); - - $Article->query($query, $params); - } - -/** - * testVeryStrangeUseCase method - * - * @expectedException PDOException - * @return void - */ - public function testVeryStrangeUseCase() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $Article = new Article(); - - $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; - $param = array( - $this->db->fullTableName('articles'), - $this->db->fullTableName('articles') . '.user_id', '3', - $this->db->fullTableName('articles') . '.published', 'Y' - ); - - $Article->query($query, $param); - } - -/** - * testRecursiveUnbind method - * - * @return void - */ - public function testRecursiveUnbind() { - $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); - - $this->loadFixtures('Apple', 'Sample'); - $TestModel = new Apple(); - $TestModel->recursive = 2; - - $result = $TestModel->find('all'); - $expected = array( + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1' - )), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - )), - 'Child' => array() + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' ), array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Sample' => array() - ))), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => - 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array())); - $this->assertEquals($expected, $result); - - $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17'), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', 'modified' => - '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1' - )), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - )), - 'Child' => array() + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' ), array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Sample' => array() - ))), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array() - )); - - $this->assertEquals($expected, $result); - - $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); - $this->assertTrue($result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', @@ -1891,73 +520,8 @@ class ModelReadTest extends BaseModelTest { 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( + ), + array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', @@ -1966,8 +530,86 @@ class ModelReadTest extends BaseModelTest { 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' - ), + ))))), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', @@ -1975,119 +617,58 @@ class ModelReadTest extends BaseModelTest { 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' ))), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', @@ -2096,44 +677,186 @@ class ModelReadTest extends BaseModelTest { 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' )), - array( - 'Apple' => array( + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), + 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', @@ -2142,8 +865,490 @@ class ModelReadTest extends BaseModelTest { 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17' - ), + ))))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array() + ))), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => + 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array())); + $this->assertEquals($expected, $result); + + $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17'), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', 'modified' => + '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', @@ -2151,5826 +1356,6787 @@ class ModelReadTest extends BaseModelTest { 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + )), + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ))); - - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); - $this->assertTrue($result); - - $result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - )), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1' - )), - array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - )), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - )), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent'))); - $this->assertTrue($result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => - '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17'), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', 'modified' => - '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ))); - $this->assertEquals($expected, $result); - } - -/** - * testSelfAssociationAfterFind method - * - * @return void - */ - public function testSelfAssociationAfterFind() { - $this->loadFixtures('Apple', 'Sample'); - $afterFindModel = new NodeAfterFind(); - $afterFindModel->recursive = 3; - $afterFindData = $afterFindModel->find('all'); - - $duplicateModel = new NodeAfterFind(); - $duplicateModel->recursive = 3; - - $noAfterFindModel = new NodeNoAfterFind(); - $noAfterFindModel->recursive = 3; - $noAfterFindData = $noAfterFindModel->find('all'); - - $this->assertFalse($afterFindModel == $noAfterFindModel); - $this->assertEquals($afterFindData, $noAfterFindData); - } - -/** - * Test that afterFind can completely unset data. - * - * @return void - */ - public function testAfterFindUnset() { - $this->loadFixtures('Article', 'Comment', 'User'); - $model = new CustomArticle(); - $model->bindModel(array( - 'hasMany' => array( - 'ModifiedComment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ) - )); - $model->ModifiedComment->remove = true; - $result = $model->find('all'); - $this->assertTrue( - empty($result[0]['ModifiedComment']), - 'Zeroith row should be removed by afterFind' - ); - } - -/** - * testFindThreadedNoParent method - * - * @return void - */ - public function testFindThreadedNoParent() { - $this->loadFixtures('Apple', 'Sample'); - $Apple = new Apple(); - $result = $Apple->find('threaded'); - $result = Hash::extract($result, '{n}.children'); - $expected = array(array(), array(), array(), array(), array(), array(), array()); - $this->assertEquals($expected, $result); - } - -/** - * testFindThreaded method - * - * @return void - */ - public function testFindThreaded() { - $this->loadFixtures('Person'); - $Model = new Person(); - $Model->recursive = -1; - $result = $Model->find('threaded'); - $result = Hash::extract($result, '{n}.children'); - $expected = array(array(), array(), array(), array(), array(), array(), array()); - $this->assertEquals($expected, $result); - - $result = $Model->find('threaded', array('parent' => 'mother_id')); - $expected = array( - array( - 'Person' => array( - 'id' => '4', - 'name' => 'mother - grand mother', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array( - array( - 'Person' => array( - 'id' => '2', - 'name' => 'mother', - 'mother_id' => '4', - 'father_id' => '5' - ), - 'children' => array( - array( - 'Person' => array( - 'id' => '1', - 'name' => 'person', - 'mother_id' => '2', - 'father_id' => '3' - ), - 'children' => array() - ) - ) - ) - ) + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( array( - 'Person' => array( - 'id' => '5', - 'name' => 'mother - grand father', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array() + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' ), + 'Sample' => array() + ))), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Child' => array( array( - 'Person' => array( - 'id' => '6', - 'name' => 'father - grand mother', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array( - array( - 'Person' => array( - 'id' => '3', - 'name' => 'father', - 'mother_id' => '6', - 'father_id' => '7' - ), - 'children' => array() - ) - ) - ), - array( - 'Person' => array( - 'id' => '7', - 'name' => 'father - grand father', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array() - ) - ); - $this->assertEquals($expected, $result); - } - -/** - * testFindAllThreaded method - * - * @return void - */ - public function testFindAllThreaded() { - $this->loadFixtures('Category'); - $TestModel = new Category(); - - $result = $TestModel->find('threaded'); - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 1%') + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array() )); - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name' - )); - - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array('order' => 'id DESC')); - - $expected = array( - array( - 'Category' => array( - 'id' => 5, - 'parent_id' => 0, - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => 4, - 'parent_id' => 0, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => 3, - 'parent_id' => 1, - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 3%') - )); - $expected = array( - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 1.1%') - )); - $expected = array( - array('Category' => - array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name', - 'conditions' => array('Category.id !=' => 2) - )); - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'fields' => 'id, name, parent_id', - 'conditions' => array('Category.id !=' => 1) - )); - $expected = array( - array('Category' => array( - 'id' => '2', - 'name' => 'Category 1.1', - 'parent_id' => '1' - )), - array('Category' => array( - 'id' => '3', - 'name' => 'Category 1.2', - 'parent_id' => '1' - )), - array('Category' => array( - 'id' => '4', - 'name' => 'Category 2', - 'parent_id' => '0' - )), - array('Category' => array( - 'id' => '5', - 'name' => 'Category 3', - 'parent_id' => '0' - )), - array('Category' => array( - 'id' => '6', - 'name' => 'Category 3.1', - 'parent_id' => '5' - )), - array('Category' => array( - 'id' => '7', - 'name' => 'Category 1.1.1', - 'parent_id' => '2' - )), - array('Category' => array( - 'id' => '8', - 'name' => 'Category 1.1.2', - 'parent_id' => '2' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name', - 'conditions' => array('Category.id !=' => 1) - )); - $expected = array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ); - $this->assertEquals($expected, $result); - } - -/** - * test find('neighbors') - * - * @return void - */ - public function testFindNeighbors() { - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); - $TestModel = new Article(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('fields' => array('id'))); - - $this->assertNull($result['prev']); - $this->assertEquals(array('id' => 2), $result['next']['Article']); - $this->assertEquals(2, count($result['next']['Comment'])); - $this->assertEquals(2, count($result['next']['Tag'])); - - $TestModel->id = 2; - $TestModel->recursive = 0; - $result = $TestModel->find('neighbors', array( - 'fields' => array('id') - )); - - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1 - )), - 'next' => array( - 'Article' => array( - 'id' => 3 - ))); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $TestModel->recursive = 1; - $result = $TestModel->find('neighbors', array('fields' => array('id'))); - - $this->assertNull($result['next']); - $this->assertEquals(array('id' => 2), $result['prev']['Article']); - $this->assertEquals(2, count($result['prev']['Comment'])); - $this->assertEquals(2, count($result['prev']['Tag'])); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => null, - 'next' => array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ) - ); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - 'next' => array( - 'Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ) - ) - ); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ), - 'next' => null - ); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 0; - $TestModel->id = 1; - $one = $TestModel->read(); - $TestModel->id = 2; - $two = $TestModel->read(); - $TestModel->id = 3; - $three = $TestModel->read(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => null, 'next' => $two); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => $one, 'next' => $three); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => $two, 'next' => null); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 2; - $TestModel->id = 1; - $one = $TestModel->read(); - $TestModel->id = 2; - $two = $TestModel->read(); - $TestModel->id = 3; - $three = $TestModel->read(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => null, 'next' => $two); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => $one, 'next' => $three); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => $two, 'next' => null); - $this->assertEquals($expected, $result); - } - -/** - * Test find(neighbors) with missing fields so no neighbors are found. - * - * @return void - */ - public function testFindNeighborsNoPrev() { - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); - $Article = new Article(); - - $result = $Article->find('neighbors', array( - 'field' => 'Article.title', - 'value' => 'Second Article', - 'fields' => array('id'), - 'conditions' => array( - 'Article.title LIKE' => '%Article%' - ), - 'recursive' => 0, - )); - $expected = array( - 'prev' => null, - 'next' => null - ); - $this->assertEquals($expected, $result); - } - -/** - * testFindCombinedRelations method - * - * @return void - */ - public function testFindCombinedRelations() { - $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); - - $this->loadFixtures('Apple', 'Sample'); - $TestModel = new Apple(); - - $result = $TestModel->find('all'); - - $expected = array( - array( - 'Apple' => array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array( - array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '2', - 'apple_id' => '2', - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => '3', - 'apple_id' => '2', - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '3', - 'apple_id' => '2', - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '1', - 'apple_id' => '3', - 'name' => 'sample1' - ), - 'Child' => array() - ), - array( - 'Apple' => array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '3', - 'apple_id' => '4', - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '4', - 'apple_id' => '5', - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array( - array( - 'id' => '7', - 'apple_id' => '6', - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '7', - 'apple_id' => '6', - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array() - )); - $this->assertEquals($expected, $result); - } - -/** - * testSaveEmpty method - * - * @return void - */ - public function testSaveEmpty() { - $this->loadFixtures('Thread'); - $TestModel = new Thread(); - $data = array(); - $expected = $TestModel->save($data); - $this->assertFalse($expected); - } - -/** - * testFindAllWithConditionInChildQuery - * - * @return void - */ - public function testFindAllWithConditionInChildQuery() { - $this->loadFixtures('Basket', 'FilmFile'); - - $TestModel = new Basket(); - $recursive = 3; - $result = $TestModel->find('all', compact('recursive')); - - $expected = array( - array( - 'Basket' => array( - 'id' => 1, - 'type' => 'nonfile', - 'name' => 'basket1', - 'object_id' => 1, - 'user_id' => 1, - ), - 'FilmFile' => array( - 'id' => '', - 'name' => '', - ) - ), - array( - 'Basket' => array( - 'id' => 2, - 'type' => 'file', - 'name' => 'basket2', - 'object_id' => 2, - 'user_id' => 1, - ), - 'FilmFile' => array( - 'id' => 2, - 'name' => 'two', - ) - ), - ); - $this->assertEquals($expected, $result); - } - -/** - * testFindAllWithConditionsHavingMixedDataTypes method - * - * @return void - */ - public function testFindAllWithConditionsHavingMixedDataTypes() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $TestModel = new Article(); - $expected = array( - array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ) - ); - $conditions = array('id' => array('1', 2)); - $recursive = -1; - $order = 'Article.id ASC'; - $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); - $this->assertEquals($expected, $result); - - $this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.'); - - $conditions = array('id' => array('1', 2, '3.0')); - $order = 'Article.id ASC'; - $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); - $expected = array( - array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ), - array( - 'Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ) - ) - ); - $this->assertEquals($expected, $result); - } - -/** - * testBindUnbind method - * - * @return void - */ - public function testBindUnbind() { - $this->loadFixtures( - 'User', - 'Comment', - 'FeatureSet', - 'DeviceType', - 'DeviceTypeCategory', - 'ExteriorTypeCategory', - 'Device', - 'Document', - 'DocumentDirectory' - ); - $TestModel = new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEquals($expected, $result); - - $TestModel->resetAssociations(); - $result = $TestModel->hasMany; - $this->assertSame(array(), $result); - - $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEquals($expected, $result); - - $result = $TestModel->hasMany; - $expected = array( - 'Comment' => array( - 'className' => 'Comment', - 'foreignKey' => 'user_id', - 'conditions' => null, - 'fields' => null, - 'order' => null, - 'limit' => null, - 'offset' => null, - 'dependent' => null, - 'exclusive' => null, - 'finderQuery' => null, - 'counterQuery' => null - )); - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); - $this->assertTrue($result); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => - 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEquals($expected, $result); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array('hasMany' => array( - 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEquals($expected, $result); - - $TestModel2 = new DeviceType(); - - $expected = array( - 'className' => 'FeatureSet', - 'foreignKey' => 'feature_set_id', - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'counterCache' => '' - ); - $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); - - $TestModel2->bindModel(array( - 'belongsTo' => array( - 'FeatureSet' => array( - 'className' => 'FeatureSet', - 'conditions' => array('active' => true) - ) - ) - )); - $expected['conditions'] = array('active' => true); - $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); - - $TestModel2->bindModel(array( - 'belongsTo' => array( - 'FeatureSet' => array( - 'className' => 'FeatureSet', - 'foreignKey' => false, - 'conditions' => array('Feature.name' => 'DeviceType.name') - ) - ) - )); - $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); - $expected['foreignKey'] = false; - $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); - - $TestModel2->bindModel(array( - 'hasMany' => array( - 'NewFeatureSet' => array( - 'className' => 'FeatureSet', - 'conditions' => array('active' => true) - ) - ) - )); - - $expected = array( - 'className' => 'FeatureSet', - 'conditions' => array('active' => true), - 'foreignKey' => 'device_type_id', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'dependent' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ); - $this->assertEquals($expected, $TestModel2->hasMany['NewFeatureSet']); - $this->assertTrue(is_object($TestModel2->NewFeatureSet)); - } - -/** - * testBindMultipleTimes method - * - * @return void - */ - public function testBindMultipleTimes() { - $this->loadFixtures('User', 'Comment', 'Article', 'Tag', 'ArticlesTag'); - $TestModel = new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array( - 'hasMany' => array( - 'Items' => array('className' => 'Comment') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Items' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Items' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Items' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Items' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array( - 'hasMany' => array( - 'Items' => array('className' => 'Article') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Items' => array( - array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Items' => array() - ), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Items' => array( - array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Items' => array() - )); - - $this->assertEquals($expected, $result); - } - -/** - * test that multiple reset = true calls to bindModel() result in the original associations. - * - * @return void - */ - public function testBindModelMultipleTimesResetCorrectly() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new User(); - - $TestModel->bindModel(array('hasMany' => array('Comment'))); - $TestModel->bindModel(array('hasMany' => array('Comment'))); - $TestModel->resetAssociations(); - - $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind'); - } - -/** - * testBindMultipleTimes method with different reset settings - * - * @return void - */ - public function testBindMultipleTimesWithDifferentResetSettings() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array( - 'hasMany' => array('Comment') - )); - $this->assertTrue($result); - $result = $TestModel->bindModel( - array('hasMany' => array('Article')), - false - ); - $this->assertTrue($result); - - $result = array_keys($TestModel->hasMany); - $expected = array('Comment', 'Article'); - $this->assertEquals($expected, $result); - - $TestModel->resetAssociations(); - - $result = array_keys($TestModel->hasMany); - $expected = array('Article'); - $this->assertEquals($expected, $result); - } - -/** - * test that bindModel behaves with Custom primary Key associations - * - * @return void - */ - public function testBindWithCustomPrimaryKey() { - $this->loadFixtures('Story', 'StoriesTag', 'Tag'); - $Model = ClassRegistry::init('StoriesTag'); - $Model->bindModel(array( - 'belongsTo' => array( - 'Tag' => array( - 'className' => 'Tag', - 'foreignKey' => 'story' - )))); - - $result = $Model->find('all'); - $this->assertFalse(empty($result)); - } - -/** - * test that calling unbindModel() with reset == true multiple times - * leaves associations in the correct state. - * - * @return void - */ - public function testUnbindMultipleTimesResetCorrectly() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new Article10(); - - $TestModel->unbindModel(array('hasMany' => array('Comment'))); - $TestModel->unbindModel(array('hasMany' => array('Comment'))); - $TestModel->resetAssociations(); - - $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed'); - } - -/** - * testBindMultipleTimes method with different reset settings - * - * @return void - */ - public function testUnBindMultipleTimesWithDifferentResetSettings() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new Comment(); - - $result = array_keys($TestModel->belongsTo); - $expected = array('Article', 'User'); - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array( - 'belongsTo' => array('User') - )); - $this->assertTrue($result); - $result = $TestModel->unbindModel( - array('belongsTo' => array('Article')), - false - ); - $this->assertTrue($result); - - $result = array_keys($TestModel->belongsTo); - $expected = array(); - $this->assertEquals($expected, $result); - - $TestModel->resetAssociations(); - - $result = array_keys($TestModel->belongsTo); - $expected = array('User'); - $this->assertEquals($expected, $result); - } - -/** - * testAssociationAfterFind method - * - * @return void - */ - public function testAssociationAfterFind() { - $this->loadFixtures('Post', 'Author', 'Comment'); - $TestModel = new Post(); - $result = $TestModel->find('all', array( - 'order' => array('Post.id' => 'ASC') - )); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - )), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31', - 'test' => 'working' - )), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - ))); - $this->assertEquals($expected, $result); - unset($TestModel); - - $Author = new Author(); - $Author->Post->bindModel(array( - 'hasMany' => array( - 'Comment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ))); - $result = $Author->find('all', array( - 'conditions' => array('Author.id' => 1), - 'order' => array('Author.id' => 'ASC'), - 'recursive' => 2 - )); - $expected = array( + $this->assertEquals($expected, $result); + + $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); + $this->assertTrue($result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, - 'comment' => 'First Comment for First Article', + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); + + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); + $this->assertTrue($result); + + $result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + )), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + )), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + )), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent'))); + $this->assertTrue($result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => + '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17'), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', 'modified' => + '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); + $this->assertEquals($expected, $result); + } + + /** + * testSelfAssociationAfterFind method + * + * @return void + */ + public function testSelfAssociationAfterFind() { + $this->loadFixtures('Apple', 'Sample'); + $afterFindModel = new NodeAfterFind(); + $afterFindModel->recursive = 3; + $afterFindData = $afterFindModel->find('all'); + + $duplicateModel = new NodeAfterFind(); + $duplicateModel->recursive = 3; + + $noAfterFindModel = new NodeNoAfterFind(); + $noAfterFindModel->recursive = 3; + $noAfterFindData = $noAfterFindModel->find('all'); + + $this->assertFalse($afterFindModel == $noAfterFindModel); + $this->assertEquals($afterFindData, $noAfterFindData); + } + + /** + * Test that afterFind can completely unset data. + * + * @return void + */ + public function testAfterFindUnset() { + $this->loadFixtures('Article', 'Comment', 'User'); + $model = new CustomArticle(); + $model->bindModel(array( + 'hasMany' => array( + 'ModifiedComment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ) + )); + $model->ModifiedComment->remove = true; + $result = $model->find('all'); + $this->assertTrue( + empty($result[0]['ModifiedComment']), 'Zeroith row should be removed by afterFind' + ); + } + + /** + * testFindThreadedNoParent method + * + * @return void + */ + public function testFindThreadedNoParent() { + $this->loadFixtures('Apple', 'Sample'); + $Apple = new Apple(); + $result = $Apple->find('threaded'); + $result = Hash::extract($result, '{n}.children'); + $expected = array(array(), array(), array(), array(), array(), array(), array()); + $this->assertEquals($expected, $result); + } + + /** + * testFindThreaded method + * + * @return void + */ + public function testFindThreaded() { + $this->loadFixtures('Person'); + $Model = new Person(); + $Model->recursive = -1; + $result = $Model->find('threaded'); + $result = Hash::extract($result, '{n}.children'); + $expected = array(array(), array(), array(), array(), array(), array(), array()); + $this->assertEquals($expected, $result); + + $result = $Model->find('threaded', array('parent' => 'mother_id')); + $expected = array( + array( + 'Person' => array( + 'id' => '4', + 'name' => 'mother - grand mother', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array( + array( + 'Person' => array( + 'id' => '2', + 'name' => 'mother', + 'mother_id' => '4', + 'father_id' => '5' + ), + 'children' => array( + array( + 'Person' => array( + 'id' => '1', + 'name' => 'person', + 'mother_id' => '2', + 'father_id' => '3' + ), + 'children' => array() + ) + ) + ) + ) + ), + array( + 'Person' => array( + 'id' => '5', + 'name' => 'mother - grand father', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array() + ), + array( + 'Person' => array( + 'id' => '6', + 'name' => 'father - grand mother', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array( + array( + 'Person' => array( + 'id' => '3', + 'name' => 'father', + 'mother_id' => '6', + 'father_id' => '7' + ), + 'children' => array() + ) + ) + ), + array( + 'Person' => array( + 'id' => '7', + 'name' => 'father - grand father', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array() + ) + ); + $this->assertEquals($expected, $result); + } + + /** + * testFindAllThreaded method + * + * @return void + */ + public function testFindAllThreaded() { + $this->loadFixtures('Category'); + $TestModel = new Category(); + + $result = $TestModel->find('threaded'); + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1%') + )); + + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name' + )); + + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array('order' => 'id DESC')); + + $expected = array( + array( + 'Category' => array( + 'id' => 5, + 'parent_id' => 0, + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => 4, + 'parent_id' => 0, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => 3, + 'parent_id' => 1, + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ) + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 3%') + )); + $expected = array( + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1.1%') + )); + $expected = array( + array('Category' => + array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 2) + )); + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'fields' => 'id, name, parent_id', + 'conditions' => array('Category.id !=' => 1) + )); + $expected = array( + array('Category' => array( + 'id' => '2', + 'name' => 'Category 1.1', + 'parent_id' => '1' + )), + array('Category' => array( + 'id' => '3', + 'name' => 'Category 1.2', + 'parent_id' => '1' + )), + array('Category' => array( + 'id' => '4', + 'name' => 'Category 2', + 'parent_id' => '0' + )), + array('Category' => array( + 'id' => '5', + 'name' => 'Category 3', + 'parent_id' => '0' + )), + array('Category' => array( + 'id' => '6', + 'name' => 'Category 3.1', + 'parent_id' => '5' + )), + array('Category' => array( + 'id' => '7', + 'name' => 'Category 1.1.1', + 'parent_id' => '2' + )), + array('Category' => array( + 'id' => '8', + 'name' => 'Category 1.1.2', + 'parent_id' => '2' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 1) + )); + $expected = array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ); + $this->assertEquals($expected, $result); + } + + /** + * test find('neighbors') + * + * @return void + */ + public function testFindNeighbors() { + $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); + $TestModel = new Article(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('fields' => array('id'))); + + $this->assertNull($result['prev']); + $this->assertEquals(array('id' => 2), $result['next']['Article']); + $this->assertEquals(2, count($result['next']['Comment'])); + $this->assertEquals(2, count($result['next']['Tag'])); + + $TestModel->id = 2; + $TestModel->recursive = 0; + $result = $TestModel->find('neighbors', array( + 'fields' => array('id') + )); + + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1 + )), + 'next' => array( + 'Article' => array( + 'id' => 3 + ))); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $TestModel->recursive = 1; + $result = $TestModel->find('neighbors', array('fields' => array('id'))); + + $this->assertNull($result['next']); + $this->assertEquals(array('id' => 2), $result['prev']['Article']); + $this->assertEquals(2, count($result['prev']['Comment'])); + $this->assertEquals(2, count($result['prev']['Tag'])); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => null, + 'next' => array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ) + ); + $this->assertEquals($expected, $result); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + 'next' => array( + 'Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ) + ) + ); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ), + 'next' => null + ); + $this->assertEquals($expected, $result); + + $TestModel->recursive = 0; + $TestModel->id = 1; + $one = $TestModel->read(); + $TestModel->id = 2; + $two = $TestModel->read(); + $TestModel->id = 3; + $three = $TestModel->read(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => null, 'next' => $two); + $this->assertEquals($expected, $result); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => $one, 'next' => $three); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => $two, 'next' => null); + $this->assertEquals($expected, $result); + + $TestModel->recursive = 2; + $TestModel->id = 1; + $one = $TestModel->read(); + $TestModel->id = 2; + $two = $TestModel->read(); + $TestModel->id = 3; + $three = $TestModel->read(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => null, 'next' => $two); + $this->assertEquals($expected, $result); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => $one, 'next' => $three); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => $two, 'next' => null); + $this->assertEquals($expected, $result); + } + + /** + * Test find(neighbors) with missing fields so no neighbors are found. + * + * @return void + */ + public function testFindNeighborsNoPrev() { + $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); + $Article = new Article(); + + $result = $Article->find('neighbors', array( + 'field' => 'Article.title', + 'value' => 'Second Article', + 'fields' => array('id'), + 'conditions' => array( + 'Article.title LIKE' => '%Article%' + ), + 'recursive' => 0, + )); + $expected = array( + 'prev' => null, + 'next' => null + ); + $this->assertEquals($expected, $result); + } + + /** + * testFindCombinedRelations method + * + * @return void + */ + public function testFindCombinedRelations() { + $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); + + $this->loadFixtures('Apple', 'Sample'); + $TestModel = new Apple(); + + $result = $TestModel->find('all'); + + $expected = array( + array( + 'Apple' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '2', + 'apple_id' => '2', + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '1', + 'apple_id' => '3', + 'name' => 'sample1' + ), + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '3', + 'apple_id' => '4', + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '4', + 'apple_id' => '5', + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array() + )); + $this->assertEquals($expected, $result); + } + + /** + * testSaveEmpty method + * + * @return void + */ + public function testSaveEmpty() { + $this->loadFixtures('Thread'); + $TestModel = new Thread(); + $data = array(); + $expected = $TestModel->save($data); + $this->assertFalse($expected); + } + + /** + * testFindAllWithConditionInChildQuery + * + * @return void + */ + public function testFindAllWithConditionInChildQuery() { + $this->loadFixtures('Basket', 'FilmFile'); + + $TestModel = new Basket(); + $recursive = 3; + $result = $TestModel->find('all', compact('recursive')); + + $expected = array( + array( + 'Basket' => array( + 'id' => 1, + 'type' => 'nonfile', + 'name' => 'basket1', + 'object_id' => 1, + 'user_id' => 1, + ), + 'FilmFile' => array( + 'id' => '', + 'name' => '', + ) + ), + array( + 'Basket' => array( + 'id' => 2, + 'type' => 'file', + 'name' => 'basket2', + 'object_id' => 2, + 'user_id' => 1, + ), + 'FilmFile' => array( + 'id' => 2, + 'name' => 'two', + ) + ), + ); + $this->assertEquals($expected, $result); + } + + /** + * testFindAllWithConditionsHavingMixedDataTypes method + * + * @return void + */ + public function testFindAllWithConditionsHavingMixedDataTypes() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $TestModel = new Article(); + $expected = array( + array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ) + ); + $conditions = array('id' => array('1', 2)); + $recursive = -1; + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); + $this->assertEquals($expected, $result); + + $this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.'); + + $conditions = array('id' => array('1', 2, '3.0')); + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); + $expected = array( + array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ), + array( + 'Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ) + ) + ); + $this->assertEquals($expected, $result); + } + + /** + * testBindUnbind method + * + * @return void + */ + public function testBindUnbind() { + $this->loadFixtures( + 'User', 'Comment', 'FeatureSet', 'DeviceType', 'DeviceTypeCategory', 'ExteriorTypeCategory', 'Device', 'Document', 'DocumentDirectory' + ); + $TestModel = new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31', - 'callback' => 'Fire' - ); - $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); - } - -/** - * testDeeperAssociationAfterFind method - * - * @return void - */ - public function testDeeperAssociationAfterFind() { - $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article'); - - $Post = new Post(); - $Post->bindModel(array( - 'hasMany' => array( - 'Comment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ))); - $Post->Comment->bindModel(array( - 'hasOne' => array( - 'Attachment' => array( - 'className' => 'ModifiedAttachment', - ) - ))); - - $result = $Post->find('first', array( - 'conditions' => array('Post.id' => 2), - 'recursive' => 2 - )); - $this->assertTrue(isset($result['Comment'][0]['callback'])); - $this->assertEquals('Fire', $result['Comment'][0]['callback']); - $this->assertTrue(isset($result['Comment'][0]['Attachment']['callback'])); - $this->assertEquals('Fired', $result['Comment'][0]['Attachment']['callback']); - } - -/** - * Tests that callbacks can be properly disabled - * - * @return void - */ - public function testCallbackDisabling() { - $this->loadFixtures('Author'); - $TestModel = new ModifiedAuthor(); - - $result = Hash::extract($TestModel->find('all'), '{n}.Author.user'); - $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); - $this->assertEquals($expected, $result); - - $result = Hash::extract($TestModel->find('all', array('callbacks' => 'after')), '{n}.Author.user'); - $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); - $this->assertEquals($expected, $result); - - $result = Hash::extract($TestModel->find('all', array('callbacks' => 'before')), '{n}.Author.user'); - $expected = array('mariano', 'nate', 'larry', 'garrett'); - $this->assertEquals($expected, $result); - - $result = Hash::extract($TestModel->find('all', array('callbacks' => false)), '{n}.Author.user'); - $expected = array('mariano', 'nate', 'larry', 'garrett'); - $this->assertEquals($expected, $result); - } - -/** - * testAssociationAfterFindCallbacksDisabled method - * - * @return void - */ - public function testAssociationAfterFindCalbacksDisabled() { - $this->loadFixtures('Post', 'Author', 'Comment'); - $TestModel = new Post(); - $result = $TestModel->find('all', array( - 'callbacks' => false, - 'order' => array('Post.id' => 'ASC'), - )); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ))); - $this->assertEquals($expected, $result); - unset($TestModel); - - $Author = new Author(); - $Author->Post->bindModel(array( - 'hasMany' => array( - 'Comment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ))); - $result = $Author->find('all', array( - 'conditions' => array('Author.id' => 1), - 'recursive' => 2, - 'order' => array('Author.id' => 'ASC'), - 'callbacks' => false - )); - $expected = array( - 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31' - ); - $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); - } - -/** - * Tests that the database configuration assigned to the model can be changed using - * (before|after)Find callbacks - * - * @return void - */ - public function testCallbackSourceChange() { - $this->loadFixtures('Post'); - $TestModel = new Post(); - $this->assertEquals(3, count($TestModel->find('all'))); - } - -/** - * testCallbackSourceChangeUnknownDatasource method - * - * @expectedException MissingDatasourceConfigException - * @return void - */ - public function testCallbackSourceChangeUnknownDatasource() { - $this->loadFixtures('Post', 'Author'); - $TestModel = new Post(); - $this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); - } - -/** - * testMultipleBelongsToWithSameClass method - * - * @return void - */ - public function testMultipleBelongsToWithSameClass() { - $this->loadFixtures( - 'DeviceType', - 'DeviceTypeCategory', - 'FeatureSet', - 'ExteriorTypeCategory', - 'Document', - 'Device', - 'DocumentDirectory' - ); - - $DeviceType = new DeviceType(); - - $DeviceType->recursive = 2; - $result = $DeviceType->read(null, 1); - - $expected = array( - 'DeviceType' => array( - 'id' => 1, - 'device_type_category_id' => 1, - 'feature_set_id' => 1, - 'exterior_type_category_id' => 1, - 'image_id' => 1, - 'extra1_id' => 1, - 'extra2_id' => 1, - 'name' => 'DeviceType 1', - 'order' => 0 - ), - 'Image' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'Extra1' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'Extra2' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'DeviceTypeCategory' => array( - 'id' => 1, - 'name' => 'DeviceTypeCategory 1' - ), - 'FeatureSet' => array( - 'id' => 1, - 'name' => 'FeatureSet 1' - ), - 'ExteriorTypeCategory' => array( - 'id' => 1, - 'image_id' => 1, - 'name' => 'ExteriorTypeCategory 1', - 'Image' => array( - 'id' => 1, - 'device_type_id' => 1, - 'name' => 'Device 1', - 'typ' => 1 - )), - 'Device' => array( - array( - 'id' => 1, - 'device_type_id' => 1, - 'name' => 'Device 1', - 'typ' => 1 - ), - array( - 'id' => 2, - 'device_type_id' => 1, - 'name' => 'Device 2', - 'typ' => 1 - ), - array( - 'id' => 3, - 'device_type_id' => 1, - 'name' => 'Device 3', - 'typ' => 2 - ))); - - $this->assertEquals($expected, $result); - } - -/** - * testHabtmRecursiveBelongsTo method - * - * @return void - */ - public function testHabtmRecursiveBelongsTo() { - $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); - $Portfolio = new Portfolio(); - - $result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3)); - $expected = array( - 'Portfolio' => array( - 'id' => 2, - 'seller_id' => 1, - 'name' => 'Portfolio 2' - ), - 'Item' => array( - array( - 'id' => 2, - 'syfile_id' => 2, - 'published' => false, - 'name' => 'Item 2', - 'ItemsPortfolio' => array( - 'id' => 2, - 'item_id' => 2, - 'portfolio_id' => 2 - ), - 'Syfile' => array( - 'id' => 2, - 'image_id' => 2, - 'name' => 'Syfile 2', - 'item_count' => null, - 'Image' => array( - 'id' => 2, - 'name' => 'Image 2' - ) - )), - array( - 'id' => 6, - 'syfile_id' => 6, - 'published' => false, - 'name' => 'Item 6', - 'ItemsPortfolio' => array( - 'id' => 6, - 'item_id' => 6, - 'portfolio_id' => 2 - ), - 'Syfile' => array( - 'id' => 6, - 'image_id' => null, - 'name' => 'Syfile 6', - 'item_count' => null, - 'Image' => array() + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' )))); - $this->assertEquals($expected, $result); - } + $this->assertEquals($expected, $result); -/** - * testNonNumericHabtmJoinKey method - * - * @return void - */ - public function testNonNumericHabtmJoinKey() { - $this->loadFixtures('Post', 'Tag', 'PostsTag', 'Author'); - $Post = new Post(); - $Post->bindModel(array( - 'hasAndBelongsToMany' => array('Tag') - )); - $Post->Tag->primaryKey = 'tag'; + $TestModel->resetAssociations(); + $result = $TestModel->hasMany; + $this->assertSame(array(), $result); - $result = $Post->find('all', array( - 'order' => 'Post.id ASC', - )); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => 1, - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => 3, - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31', - 'test' => 'working' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => 1, - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - ), - 'Tag' => array() - )); - $this->assertEquals($expected, $result); - } + $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); + $this->assertTrue($result); -/** - * testHabtmFinderQuery method - * - * @return void - */ - public function testHabtmFinderQuery() { - $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); - $Article = new Article(); - - $sql = $this->db->buildStatement( - array( - 'fields' => $this->db->fields($Article->Tag, null, array( - 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id' - )), - 'table' => $this->db->fullTableName('tags'), - 'alias' => 'Tag', - 'limit' => null, - 'offset' => null, - 'group' => null, - 'joins' => array(array( - 'alias' => 'ArticlesTag', - 'table' => 'articles_tags', - 'conditions' => array( - array("ArticlesTag.article_id" => '{$__cakeID__$}'), - array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) - ) - )), - 'conditions' => array(), - 'order' => null - ), - $Article - ); - - $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; - $result = $Article->find('first'); - $expected = array( - array( - 'id' => '1', - 'tag' => 'tag1' - ), - array( - 'id' => '2', - 'tag' => 'tag2' + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), )); - $this->assertEquals($expected, $result['Tag']); - } + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); -/** - * testHabtmLimitOptimization method - * - * @return void - */ - public function testHabtmLimitOptimization() { - $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); - $TestModel = new Article(); + $this->assertEquals($expected, $result); - $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; - $result = $TestModel->read(null, 2); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' + $result = $TestModel->hasMany; + $expected = array( + 'Comment' => array( + 'className' => 'Comment', + 'foreignKey' => 'user_id', + 'conditions' => null, + 'fields' => null, + 'order' => null, + 'limit' => null, + 'offset' => null, + 'dependent' => null, + 'exclusive' => null, + 'finderQuery' => null, + 'counterQuery' => null + )); + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $this->assertTrue($result); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => + 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEquals($expected, $result); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array('hasMany' => array( + 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + + $this->assertEquals($expected, $result); + + $TestModel2 = new DeviceType(); + + $expected = array( + 'className' => 'FeatureSet', + 'foreignKey' => 'feature_set_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'counterCache' => '' + ); + $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); + + $TestModel2->bindModel(array( + 'belongsTo' => array( + 'FeatureSet' => array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true) + ) + ) + )); + $expected['conditions'] = array('active' => true); + $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); + + $TestModel2->bindModel(array( + 'belongsTo' => array( + 'FeatureSet' => array( + 'className' => 'FeatureSet', + 'foreignKey' => false, + 'conditions' => array('Feature.name' => 'DeviceType.name') + ) + ) + )); + $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); + $expected['foreignKey'] = false; + $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); + + $TestModel2->bindModel(array( + 'hasMany' => array( + 'NewFeatureSet' => array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true) + ) + ) + )); + + $expected = array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true), + 'foreignKey' => 'device_type_id', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'dependent' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ); + $this->assertEquals($expected, $TestModel2->hasMany['NewFeatureSet']); + $this->assertTrue(is_object($TestModel2->NewFeatureSet)); + } + + /** + * testBindMultipleTimes method + * + * @return void + */ + public function testBindMultipleTimes() { + $this->loadFixtures('User', 'Comment', 'Article', 'Tag', 'ArticlesTag'); + $TestModel = new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Comment') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Items' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Article') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array( + array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Items' => array() + )); + + $this->assertEquals($expected, $result); + } + + /** + * test that multiple reset = true calls to bindModel() result in the original associations. + * + * @return void + */ + public function testBindModelMultipleTimesResetCorrectly() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new User(); + + $TestModel->bindModel(array('hasMany' => array('Comment'))); + $TestModel->bindModel(array('hasMany' => array('Comment'))); + $TestModel->resetAssociations(); + + $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind'); + } + + /** + * testBindMultipleTimes method with different reset settings + * + * @return void + */ + public function testBindMultipleTimesWithDifferentResetSettings() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array( + 'hasMany' => array('Comment') + )); + $this->assertTrue($result); + $result = $TestModel->bindModel( + array('hasMany' => array('Article')), false + ); + $this->assertTrue($result); + + $result = array_keys($TestModel->hasMany); + $expected = array('Comment', 'Article'); + $this->assertEquals($expected, $result); + + $TestModel->resetAssociations(); + + $result = array_keys($TestModel->hasMany); + $expected = array('Article'); + $this->assertEquals($expected, $result); + } + + /** + * test that bindModel behaves with Custom primary Key associations + * + * @return void + */ + public function testBindWithCustomPrimaryKey() { + $this->loadFixtures('Story', 'StoriesTag', 'Tag'); + $Model = ClassRegistry::init('StoriesTag'); + $Model->bindModel(array( + 'belongsTo' => array( + 'Tag' => array( + 'className' => 'Tag', + 'foreignKey' => 'story' + )))); + + $result = $Model->find('all'); + $this->assertFalse(empty($result)); + } + + /** + * test that calling unbindModel() with reset == true multiple times + * leaves associations in the correct state. + * + * @return void + */ + public function testUnbindMultipleTimesResetCorrectly() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new Article10(); + + $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $TestModel->resetAssociations(); + + $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed'); + } + + /** + * testBindMultipleTimes method with different reset settings + * + * @return void + */ + public function testUnBindMultipleTimesWithDifferentResetSettings() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new Comment(); + + $result = array_keys($TestModel->belongsTo); + $expected = array('Article', 'User'); + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array( + 'belongsTo' => array('User') + )); + $this->assertTrue($result); + $result = $TestModel->unbindModel( + array('belongsTo' => array('Article')), false + ); + $this->assertTrue($result); + + $result = array_keys($TestModel->belongsTo); + $expected = array(); + $this->assertEquals($expected, $result); + + $TestModel->resetAssociations(); + + $result = array_keys($TestModel->belongsTo); + $expected = array('User'); + $this->assertEquals($expected, $result); + } + + /** + * testAssociationAfterFind method + * + * @return void + */ + public function testAssociationAfterFind() { + $this->loadFixtures('Post', 'Author', 'Comment'); + $TestModel = new Post(); + $result = $TestModel->find('all', array( + 'order' => array('Post.id' => 'ASC') + )); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ))); + $this->assertEquals($expected, $result); + unset($TestModel); + + $Author = new Author(); + $Author->Post->bindModel(array( + 'hasMany' => array( + 'Comment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ))); + $result = $Author->find('all', array( + 'conditions' => array('Author.id' => 1), + 'order' => array('Author.id' => 'ASC'), + 'recursive' => 2 + )); + $expected = array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31', + 'callback' => 'Fire' + ); + $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); + } + + /** + * testDeeperAssociationAfterFind method + * + * @return void + */ + public function testDeeperAssociationAfterFind() { + $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article'); + + $Post = new Post(); + $Post->bindModel(array( + 'hasMany' => array( + 'Comment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ))); + $Post->Comment->bindModel(array( + 'hasOne' => array( + 'Attachment' => array( + 'className' => 'ModifiedAttachment', + ) ))); - $this->assertEquals($expected, $result); - - $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1; - $result = $TestModel->read(null, 2); - unset($expected['Tag'][1]); - - $this->assertEquals($expected, $result); - } - -/** - * testHasManyLimitOptimization method - * - * @return void - */ - public function testHasManyLimitOptimization() { - $this->loadFixtures('Project', 'Thread', 'Message', 'Bid'); - $Project = new Project(); - $Project->recursive = 3; - - $result = $Project->find('all', array( - 'order' => 'Project.id ASC', + $result = $Post->find('first', array( + 'conditions' => array('Post.id' => 2), + 'recursive' => 2 )); - $expected = array( - array( - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1', - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1', - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2' - ))), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1', - 'Bid' => array( - 'id' => 1, - 'message_id' => 1, - 'name' => 'Bid 1.1' - )))), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2', - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1', - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2' - ))), - 'Message' => array( - array( - 'id' => 2, - 'thread_id' => 2, - 'name' => 'Thread 2, Message 1', - 'Bid' => array( - 'id' => 4, - 'message_id' => 2, - 'name' => 'Bid 2.1' - )))))), - array( - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2' - ), - 'Thread' => array( - array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1', - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2', - 'Thread' => array( - array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1' - ))), - 'Message' => array( - array( - 'id' => 3, - 'thread_id' => 3, - 'name' => 'Thread 3, Message 1', - 'Bid' => array( - 'id' => 3, - 'message_id' => 3, - 'name' => 'Bid 3.1' - )))))), - array( - 'Project' => array( - 'id' => 3, - 'name' => 'Project 3' - ), - 'Thread' => array() + $this->assertTrue(isset($result['Comment'][0]['callback'])); + $this->assertEquals('Fire', $result['Comment'][0]['callback']); + $this->assertTrue(isset($result['Comment'][0]['Attachment']['callback'])); + $this->assertEquals('Fired', $result['Comment'][0]['Attachment']['callback']); + } + + /** + * Tests that callbacks can be properly disabled + * + * @return void + */ + public function testCallbackDisabling() { + $this->loadFixtures('Author'); + $TestModel = new ModifiedAuthor(); + + $result = Hash::extract($TestModel->find('all'), '{n}.Author.user'); + $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); + $this->assertEquals($expected, $result); + + $result = Hash::extract($TestModel->find('all', array('callbacks' => 'after')), '{n}.Author.user'); + $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); + $this->assertEquals($expected, $result); + + $result = Hash::extract($TestModel->find('all', array('callbacks' => 'before')), '{n}.Author.user'); + $expected = array('mariano', 'nate', 'larry', 'garrett'); + $this->assertEquals($expected, $result); + + $result = Hash::extract($TestModel->find('all', array('callbacks' => false)), '{n}.Author.user'); + $expected = array('mariano', 'nate', 'larry', 'garrett'); + $this->assertEquals($expected, $result); + } + + /** + * testAssociationAfterFindCallbacksDisabled method + * + * @return void + */ + public function testAssociationAfterFindCalbacksDisabled() { + $this->loadFixtures('Post', 'Author', 'Comment'); + $TestModel = new Post(); + $result = $TestModel->find('all', array( + 'callbacks' => false, + 'order' => array('Post.id' => 'ASC'), + )); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ))); + $this->assertEquals($expected, $result); + unset($TestModel); + + $Author = new Author(); + $Author->Post->bindModel(array( + 'hasMany' => array( + 'Comment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ))); + $result = $Author->find('all', array( + 'conditions' => array('Author.id' => 1), + 'recursive' => 2, + 'order' => array('Author.id' => 'ASC'), + 'callbacks' => false + )); + $expected = array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ); + $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); + } + + /** + * Tests that the database configuration assigned to the model can be changed using + * (before|after)Find callbacks + * + * @return void + */ + public function testCallbackSourceChange() { + $this->loadFixtures('Post'); + $TestModel = new Post(); + $this->assertEquals(3, count($TestModel->find('all'))); + } + + /** + * testCallbackSourceChangeUnknownDatasource method + * + * @expectedException MissingDatasourceConfigException + * @return void + */ + public function testCallbackSourceChangeUnknownDatasource() { + $this->loadFixtures('Post', 'Author'); + $TestModel = new Post(); + $this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); + } + + /** + * testMultipleBelongsToWithSameClass method + * + * @return void + */ + public function testMultipleBelongsToWithSameClass() { + $this->loadFixtures( + 'DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory' + ); + + $DeviceType = new DeviceType(); + + $DeviceType->recursive = 2; + $result = $DeviceType->read(null, 1); + + $expected = array( + 'DeviceType' => array( + 'id' => 1, + 'device_type_category_id' => 1, + 'feature_set_id' => 1, + 'exterior_type_category_id' => 1, + 'image_id' => 1, + 'extra1_id' => 1, + 'extra2_id' => 1, + 'name' => 'DeviceType 1', + 'order' => 0 + ), + 'Image' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'Extra1' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'Extra2' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'DeviceTypeCategory' => array( + 'id' => 1, + 'name' => 'DeviceTypeCategory 1' + ), + 'FeatureSet' => array( + 'id' => 1, + 'name' => 'FeatureSet 1' + ), + 'ExteriorTypeCategory' => array( + 'id' => 1, + 'image_id' => 1, + 'name' => 'ExteriorTypeCategory 1', + 'Image' => array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + )), + 'Device' => array( + array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + ), + array( + 'id' => 2, + 'device_type_id' => 1, + 'name' => 'Device 2', + 'typ' => 1 + ), + array( + 'id' => 3, + 'device_type_id' => 1, + 'name' => 'Device 3', + 'typ' => 2 + ))); + + $this->assertEquals($expected, $result); + } + + /** + * testHabtmRecursiveBelongsTo method + * + * @return void + */ + public function testHabtmRecursiveBelongsTo() { + $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); + $Portfolio = new Portfolio(); + + $result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3)); + $expected = array( + 'Portfolio' => array( + 'id' => 2, + 'seller_id' => 1, + 'name' => 'Portfolio 2' + ), + 'Item' => array( + array( + 'id' => 2, + 'syfile_id' => 2, + 'published' => false, + 'name' => 'Item 2', + 'ItemsPortfolio' => array( + 'id' => 2, + 'item_id' => 2, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 2, + 'image_id' => 2, + 'name' => 'Syfile 2', + 'item_count' => null, + 'Image' => array( + 'id' => 2, + 'name' => 'Image 2' + ) + )), + array( + 'id' => 6, + 'syfile_id' => 6, + 'published' => false, + 'name' => 'Item 6', + 'ItemsPortfolio' => array( + 'id' => 6, + 'item_id' => 6, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 6, + 'image_id' => null, + 'name' => 'Syfile 6', + 'item_count' => null, + 'Image' => array() + )))); + + $this->assertEquals($expected, $result); + } + + /** + * testNonNumericHabtmJoinKey method + * + * @return void + */ + public function testNonNumericHabtmJoinKey() { + $this->loadFixtures('Post', 'Tag', 'PostsTag', 'Author'); + $Post = new Post(); + $Post->bindModel(array( + 'hasAndBelongsToMany' => array('Tag') + )); + $Post->Tag->primaryKey = 'tag'; + + $result = $Post->find('all', array( + 'order' => 'Post.id ASC', + )); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => 3, + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31', + 'test' => 'working' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ), + 'Tag' => array() + )); + $this->assertEquals($expected, $result); + } + + /** + * testHabtmFinderQuery method + * + * @return void + */ + public function testHabtmFinderQuery() { + $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); + $Article = new Article(); + + $sql = $this->db->buildStatement( + array( + 'fields' => $this->db->fields($Article->Tag, null, array( + 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id' + )), + 'table' => $this->db->fullTableName('tags'), + 'alias' => 'Tag', + 'limit' => null, + 'offset' => null, + 'group' => null, + 'joins' => array(array( + 'alias' => 'ArticlesTag', + 'table' => 'articles_tags', + 'conditions' => array( + array("ArticlesTag.article_id" => '{$__cakeID__$}'), + array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) + ) + )), + 'conditions' => array(), + 'order' => null + ), $Article + ); + + $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; + $result = $Article->find('first'); + $expected = array( + array( + 'id' => '1', + 'tag' => 'tag1' + ), + array( + 'id' => '2', + 'tag' => 'tag2' )); - $this->assertEquals($expected, $result); - } + $this->assertEquals($expected, $result['Tag']); + } -/** - * testFindAllRecursiveSelfJoin method - * - * @return void - */ - public function testFindAllRecursiveSelfJoin() { - $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement'); - $TestModel = new Home(); - $TestModel->recursive = 2; + /** + * testHabtmLimitOptimization method + * + * @return void + */ + public function testHabtmLimitOptimization() { + $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); + $TestModel = new Article(); - $result = $TestModel->find('all', array( - 'order' => 'Home.id ASC', + $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; + $result = $TestModel->read(null, 2); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + + $this->assertEquals($expected, $result); + + $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1; + $result = $TestModel->read(null, 2); + unset($expected['Tag'][1]); + + $this->assertEquals($expected, $result); + } + + /** + * testHasManyLimitOptimization method + * + * @return void + */ + public function testHasManyLimitOptimization() { + $this->loadFixtures('Project', 'Thread', 'Message', 'Bid'); + $Project = new Project(); + $Project->recursive = 3; + + $result = $Project->find('all', array( + 'order' => 'Project.id ASC', )); - $expected = array( - array( - 'Home' => array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' + $expected = array( + array( + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' ), - 'AnotherArticle' => array( - 'id' => '1', - 'title' => 'First Article', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( - array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ))), - 'Advertisement' => array( - 'id' => '1', - 'title' => 'First Ad', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( - array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - )))), - array( - 'Home' => array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1', + 'Bid' => array( + 'id' => 1, + 'message_id' => 1, + 'name' => 'Bid 1.1' + )))), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' ), - 'AnotherArticle' => array( - 'id' => '3', - 'title' => 'Third Article', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31', - 'Home' => array( - array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))), - 'Advertisement' => array( - 'id' => '1', - 'title' => 'First Ad', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( - array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))))); - - $this->assertEquals($expected, $result); - } - -/** - * testFindAllRecursiveWithHabtm method - * - * @return void - */ - public function testFindAllRecursiveWithHabtm() { - $this->loadFixtures( - 'MyCategoriesMyUsers', - 'MyCategoriesMyProducts', - 'MyCategory', - 'MyUser', - 'MyProduct' - ); - - $MyUser = new MyUser(); - $MyUser->recursive = 2; - - $result = $MyUser->find('all', array( - 'order' => 'MyUser.id ASC' + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 2, + 'thread_id' => 2, + 'name' => 'Thread 2, Message 1', + 'Bid' => array( + 'id' => 4, + 'message_id' => 2, + 'name' => 'Bid 2.1' + )))))), + array( + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1', + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2', + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ))), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1', + 'Bid' => array( + 'id' => 3, + 'message_id' => 3, + 'name' => 'Bid 3.1' + )))))), + array( + 'Project' => array( + 'id' => 3, + 'name' => 'Project 3' + ), + 'Thread' => array() )); - $expected = array( + + $this->assertEquals($expected, $result); + } + + /** + * testFindAllRecursiveSelfJoin method + * + * @return void + */ + public function testFindAllRecursiveSelfJoin() { + $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement'); + $TestModel = new Home(); + $TestModel->recursive = 2; + + $result = $TestModel->find('all', array( + 'order' => 'Home.id ASC', + )); + $expected = array( + array( + 'Home' => array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'AnotherArticle' => array( + 'id' => '1', + 'title' => 'First Article', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( array( - 'MyUser' => array('id' => '1', 'firstname' => 'userA'), - 'MyCategory' => array( - array( - 'id' => '1', - 'name' => 'A', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ))), - array( - 'id' => '3', - 'name' => 'C', - 'MyProduct' => array( - array( - 'id' => '2', - 'name' => 'computer' + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )))), + array( + 'Home' => array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'AnotherArticle' => array( + 'id' => '3', + 'title' => 'Third Article', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'Home' => array( + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))))); + + $this->assertEquals($expected, $result); + } + + /** + * testFindAllRecursiveWithHabtm method + * + * @return void + */ + public function testFindAllRecursiveWithHabtm() { + $this->loadFixtures( + 'MyCategoriesMyUsers', 'MyCategoriesMyProducts', 'MyCategory', 'MyUser', 'MyProduct' + ); + + $MyUser = new MyUser(); + $MyUser->recursive = 2; + + $result = $MyUser->find('all', array( + 'order' => 'MyUser.id ASC' + )); + $expected = array( + array( + 'MyUser' => array('id' => '1', 'firstname' => 'userA'), + 'MyCategory' => array( + array( + 'id' => '1', + 'name' => 'A', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ))), + array( + 'id' => '3', + 'name' => 'C', + 'MyProduct' => array( + array( + 'id' => '2', + 'name' => 'computer' ))))), - array( - 'MyUser' => array( - 'id' => '2', - 'firstname' => 'userB' - ), - 'MyCategory' => array( - array( - 'id' => '1', - 'name' => 'A', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ))), - array( - 'id' => '2', - 'name' => 'B', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ), - array( - 'id' => '2', - 'name' => 'computer' - )))))); + array( + 'MyUser' => array( + 'id' => '2', + 'firstname' => 'userB' + ), + 'MyCategory' => array( + array( + 'id' => '1', + 'name' => 'A', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ))), + array( + 'id' => '2', + 'name' => 'B', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ), + array( + 'id' => '2', + 'name' => 'computer' + )))))); - $this->assertEquals($expected, $result); - } + $this->assertEquals($expected, $result); + } -/** - * testReadFakeThread method - * - * @return void - */ - public function testReadFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel = new CategoryThread(); + /** + * testReadFakeThread method + * + * @return void + */ + public function testReadFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel = new CategoryThread(); - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $TestModel->id = 7; - $result = $TestModel->read(); - $expected = array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $TestModel->id = 7; + $result = $TestModel->read(); + $expected = array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))))))); + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); - $this->db->fullDebug = $fullDebug; - $this->assertEquals($expected, $result); - } + $this->db->fullDebug = $fullDebug; + $this->assertEquals($expected, $result); + } -/** - * testFindFakeThread method - * - * @return void - */ - public function testFindFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel = new CategoryThread(); + /** + * testFindFakeThread method + * + * @return void + */ + public function testFindFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel = new CategoryThread(); - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7))); + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7))); - $expected = array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), + $expected = array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))))))); + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); - $this->db->fullDebug = $fullDebug; - $this->assertEquals($expected, $result); - } + $this->db->fullDebug = $fullDebug; + $this->assertEquals($expected, $result); + } -/** - * testFindAllFakeThread method - * - * @return void - */ - public function testFindAllFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel = new CategoryThread(); + /** + * testFindAllFakeThread method + * + * @return void + */ + public function testFindAllFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel = new CategoryThread(); - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $result = $TestModel->find('all'); - $expected = array( - array( - 'CategoryThread' => array( + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $result = $TestModel->find('all'); + $expected = array( + array( + 'CategoryThread' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => null, + 'parent_id' => null, + 'name' => null, + 'created' => null, + 'updated' => null, + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))), + array( + 'CategoryThread' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))), + array( + 'CategoryThread' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))))), + array( + 'CategoryThread' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( - 'id' => null, - 'parent_id' => null, - 'name' => null, - 'created' => null, - 'updated' => null, - 'ParentCategory' => array() - )), - array( - 'CategoryThread' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))))), + array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )), - array( - 'CategoryThread' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - ))), - array( - 'CategoryThread' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )))), - array( - 'CategoryThread' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - ))))), - array( - 'CategoryThread' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )))))), - array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - )))))))); + )))))))); - $this->db->fullDebug = $fullDebug; - $this->assertEquals($expected, $result); - } + $this->db->fullDebug = $fullDebug; + $this->assertEquals($expected, $result); + } -/** - * testConditionalNumerics method - * - * @return void - */ - public function testConditionalNumerics() { - $this->loadFixtures('NumericArticle'); - $NumericArticle = new NumericArticle(); - $data = array('conditions' => array('title' => '12345abcde')); - $result = $NumericArticle->find('first', $data); - $this->assertTrue(!empty($result)); + /** + * testConditionalNumerics method + * + * @return void + */ + public function testConditionalNumerics() { + $this->loadFixtures('NumericArticle'); + $NumericArticle = new NumericArticle(); + $data = array('conditions' => array('title' => '12345abcde')); + $result = $NumericArticle->find('first', $data); + $this->assertTrue(!empty($result)); - $data = array('conditions' => array('title' => '12345')); - $result = $NumericArticle->find('first', $data); - $this->assertTrue(empty($result)); - } + $data = array('conditions' => array('title' => '12345')); + $result = $NumericArticle->find('first', $data); + $this->assertTrue(empty($result)); + } -/** - * test buildQuery() - * - * @return void - */ - public function testBuildQuery() { - $this->loadFixtures('User'); - $TestModel = new User(); - $TestModel->cacheQueries = false; - $TestModel->order = null; + /** + * test buildQuery() + * + * @return void + */ + public function testBuildQuery() { + $this->loadFixtures('User'); + $TestModel = new User(); + $TestModel->cacheQueries = false; + $TestModel->order = null; - $expected = array( - 'conditions' => array( - 'user' => 'larry' - ), - 'fields' => null, - 'joins' => array(), - 'limit' => null, - 'offset' => null, - 'order' => array( - 0 => null - ), - 'page' => 1, - 'group' => null, - 'callbacks' => true, - 'returnQuery' => true - ); - $result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry'))); - $this->assertEquals($expected, $result); - } + $expected = array( + 'conditions' => array( + 'user' => 'larry' + ), + 'fields' => null, + 'joins' => array(), + 'limit' => null, + 'offset' => null, + 'order' => array( + 0 => null + ), + 'page' => 1, + 'group' => null, + 'callbacks' => true, + 'returnQuery' => true + ); + $result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry'))); + $this->assertEquals($expected, $result); + } -/** - * test find('all') method - * - * @return void - */ - public function testFindAll() { - $this->loadFixtures('User'); - $TestModel = new User(); - $TestModel->cacheQueries = false; + /** + * test find('all') method + * + * @return void + */ + public function testFindAll() { + $this->loadFixtures('User'); + $TestModel = new User(); + $TestModel->cacheQueries = false; - $result = $TestModel->find('all'); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); + $result = $TestModel->find('all'); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array('conditions' => 'User.id > 2')); - $expected = array( - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); + $result = $TestModel->find('all', array('conditions' => 'User.id > 2')); + $expected = array( + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array( - 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%') + $result = $TestModel->find('all', array( + 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%') )); - $expected = array( - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); + $expected = array( + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array('conditions' => array('User.id' => '0'))); - $expected = array(); - $this->assertEquals($expected, $result); + $result = $TestModel->find('all', array('conditions' => array('User.id' => '0'))); + $expected = array(); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array( - 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%') + $result = $TestModel->find('all', array( + 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%') ))); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEquals($expected, $result); + $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC')); - $expected = array( - array('User' => array('user' => 'garrett')), - array('User' => array('user' => 'larry')), - array('User' => array('user' => 'mariano')), - array('User' => array('user' => 'nate'))); - $this->assertEquals($expected, $result); + $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC')); + $expected = array( + array('User' => array('user' => 'garrett')), + array('User' => array('user' => 'larry')), + array('User' => array('user' => 'mariano')), + array('User' => array('user' => 'nate'))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC')); - $expected = array( - array('User' => array('user' => 'nate')), - array('User' => array('user' => 'mariano')), - array('User' => array('user' => 'larry')), - array('User' => array('user' => 'garrett'))); - $this->assertEquals($expected, $result); + $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC')); + $expected = array( + array('User' => array('user' => 'nate')), + array('User' => array('user' => 'mariano')), + array('User' => array('user' => 'larry')), + array('User' => array('user' => 'garrett'))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array('limit' => 3, 'page' => 1)); + $result = $TestModel->find('all', array('limit' => 3, 'page' => 1)); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ))); - $this->assertEquals($expected, $result); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ))); + $this->assertEquals($expected, $result); - $ids = array(4 => 1, 5 => 3); - $result = $TestModel->find('all', array( - 'conditions' => array('User.id' => $ids), - 'order' => 'User.id' + $ids = array(4 => 1, 5 => 3); + $result = $TestModel->find('all', array( + 'conditions' => array('User.id' => $ids), + 'order' => 'User.id' )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ))); + $this->assertEquals($expected, $result); + + // These tests are expected to fail on SQL Server since the LIMIT/OFFSET + // hack can't handle small record counts. + if (!($this->db instanceof Sqlserver)) { + $result = $TestModel->find('all', array('limit' => 3, 'page' => 2)); + $expected = array( + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' ))); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - // These tests are expected to fail on SQL Server since the LIMIT/OFFSET - // hack can't handle small record counts. - if (!($this->db instanceof Sqlserver)) { - $result = $TestModel->find('all', array('limit' => 3, 'page' => 2)); - $expected = array( - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('limit' => 3, 'page' => 3)); - $expected = array(); - $this->assertEquals($expected, $result); - } + $result = $TestModel->find('all', array('limit' => 3, 'page' => 3)); + $expected = array(); + $this->assertEquals($expected, $result); } + } -/** - * test find('list') method - * - * @return void - */ - public function testGenerateFindList() { - $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment'); + /** + * test find('list') method + * + * @return void + */ + public function testGenerateFindList() { + $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment'); - $TestModel = new Article(); - $TestModel->displayField = 'title'; + $TestModel = new Article(); + $TestModel->displayField = 'title'; - $result = $TestModel->find('list', array( - 'order' => 'Article.title ASC' + $result = $TestModel->find('list', array( + 'order' => 'Article.title ASC' )); - $expected = array( - 1 => 'First Article', - 2 => 'Second Article', - 3 => 'Third Article' - ); - $this->assertEquals($expected, $result); + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); + $this->assertEquals($expected, $result); - $db = ConnectionManager::getDataSource('test'); - if ($db instanceof Mysql) { - $result = $TestModel->find('list', array( - 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') - )); - $expected = array( - 1 => 'First Article', - 3 => 'Third Article', - 2 => 'Second Article' - ); - $this->assertEquals($expected, $result); - } + $db = ConnectionManager::getDataSource('test'); + if ($db instanceof Mysql) { + $result = $TestModel->find('list', array( + 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') + )); + $expected = array( + 1 => 'First Article', + 3 => 'Third Article', + 2 => 'Second Article' + ); + $this->assertEquals($expected, $result); + } - $result = Hash::combine( + $result = Hash::combine( $TestModel->find('all', array( - 'order' => 'Article.title ASC', - 'fields' => array('id', 'title') - )), - '{n}.Article.id', '{n}.Article.title' - ); - $expected = array( - 1 => 'First Article', - 2 => 'Second Article', - 3 => 'Third Article' - ); - $this->assertEquals($expected, $result); + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title') + )), '{n}.Article.id', '{n}.Article.title' + ); + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); + $this->assertEquals($expected, $result); - $result = Hash::combine( + $result = Hash::combine( $TestModel->find('all', array( - 'order' => 'Article.title ASC' - )), - '{n}.Article.id', '{n}.Article' - ); - $expected = array( - 1 => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 2 => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 3 => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' + 'order' => 'Article.title ASC' + )), '{n}.Article.id', '{n}.Article' + ); + $expected = array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = Hash::combine( + $result = Hash::combine( $TestModel->find('all', array( - 'order' => 'Article.title ASC' - )), - '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' - ); - $expected = array( - 1 => array( - 1 => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 3 => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - )), - 3 => array( - 2 => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))); + 'order' => 'Article.title ASC' + )), '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' + ); + $expected = array( + 1 => array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )), + 3 => array( + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = Hash::combine( + $result = Hash::combine( $TestModel->find('all', array( - 'order' => 'Article.title ASC', - 'fields' => array('id', 'title', 'user_id') - )), - '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' - ); + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title', 'user_id') + )), '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' + ); - $expected = array( - 1 => array( - 1 => 'First Article', - 3 => 'Third Article' - ), - 3 => array( - 2 => 'Second Article' + $expected = array( + 1 => array( + 1 => 'First Article', + 3 => 'Third Article' + ), + 3 => array( + 2 => 'Second Article' )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $TestModel = new Apple(); - $expected = array( - 1 => 'Red Apple 1', - 2 => 'Bright Red Apple', - 3 => 'green blue', - 4 => 'Test Name', - 5 => 'Blue Green', - 6 => 'My new apple', - 7 => 'Some odd color' - ); + $TestModel = new Apple(); + $expected = array( + 1 => 'Red Apple 1', + 2 => 'Bright Red Apple', + 3 => 'green blue', + 4 => 'Test Name', + 5 => 'Blue Green', + 6 => 'My new apple', + 7 => 'Some odd color' + ); - $this->assertEquals($expected, $TestModel->find('list')); - $this->assertEquals($expected, $TestModel->Parent->find('list')); + $this->assertEquals($expected, $TestModel->find('list')); + $this->assertEquals($expected, $TestModel->Parent->find('list')); - $TestModel = new Post(); - $result = $TestModel->find('list', array( - 'fields' => 'Post.title' + $TestModel = new Post(); + $result = $TestModel->find('list', array( + 'fields' => 'Post.title' )); - $expected = array( - 1 => 'First Post', - 2 => 'Second Post', - 3 => 'Third Post' - ); - $this->assertEquals($expected, $result); + $expected = array( + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' + ); + $this->assertEquals($expected, $result); - $result = $TestModel->find('list', array( - 'fields' => 'title' + $result = $TestModel->find('list', array( + 'fields' => 'title' )); - $expected = array( - 1 => 'First Post', - 2 => 'Second Post', - 3 => 'Third Post' - ); - $this->assertEquals($expected, $result); + $expected = array( + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' + ); + $this->assertEquals($expected, $result); - $result = $TestModel->find('list', array( - 'fields' => array('title', 'id') + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id') )); - $expected = array( - 'First Post' => '1', - 'Second Post' => '2', - 'Third Post' => '3' - ); - $this->assertEquals($expected, $result); + $expected = array( + 'First Post' => '1', + 'Second Post' => '2', + 'Third Post' => '3' + ); + $this->assertEquals($expected, $result); - $result = $TestModel->find('list', array( - 'fields' => array('title', 'id', 'created') + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id', 'created') )); - $expected = array( - '2007-03-18 10:39:23' => array( - 'First Post' => '1' - ), - '2007-03-18 10:41:23' => array( - 'Second Post' => '2' - ), - '2007-03-18 10:43:23' => array( - 'Third Post' => '3' - ), - ); - $this->assertEquals($expected, $result); + $expected = array( + '2007-03-18 10:39:23' => array( + 'First Post' => '1' + ), + '2007-03-18 10:41:23' => array( + 'Second Post' => '2' + ), + '2007-03-18 10:43:23' => array( + 'Third Post' => '3' + ), + ); + $this->assertEquals($expected, $result); - $result = $TestModel->find('list', array( - 'fields' => array('Post.body') + $result = $TestModel->find('list', array( + 'fields' => array('Post.body') )); - $expected = array( - 1 => 'First Post Body', - 2 => 'Second Post Body', - 3 => 'Third Post Body' - ); - $this->assertEquals($expected, $result); + $expected = array( + 1 => 'First Post Body', + 2 => 'Second Post Body', + 3 => 'Third Post Body' + ); + $this->assertEquals($expected, $result); - $result = $TestModel->find('list', array( - 'fields' => array('Post.title', 'Post.body') + $result = $TestModel->find('list', array( + 'fields' => array('Post.title', 'Post.body') )); - $expected = array( - 'First Post' => 'First Post Body', - 'Second Post' => 'Second Post Body', - 'Third Post' => 'Third Post Body' - ); - $this->assertEquals($expected, $result); + $expected = array( + 'First Post' => 'First Post Body', + 'Second Post' => 'Second Post Body', + 'Third Post' => 'Third Post Body' + ); + $this->assertEquals($expected, $result); - $result = $TestModel->find('list', array( - 'fields' => array('Post.id', 'Post.title', 'Author.user'), - 'recursive' => 1 + $result = $TestModel->find('list', array( + 'fields' => array('Post.id', 'Post.title', 'Author.user'), + 'recursive' => 1 )); - $expected = array( - 'mariano' => array( - 1 => 'First Post', - 3 => 'Third Post' - ), - 'larry' => array( - 2 => 'Second Post' + $expected = array( + 'mariano' => array( + 1 => 'First Post', + 3 => 'Third Post' + ), + 'larry' => array( + 2 => 'Second Post' )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $TestModel = new User(); - $result = $TestModel->find('list', array( - 'fields' => array('User.user', 'User.password') + $TestModel = new User(); + $result = $TestModel->find('list', array( + 'fields' => array('User.user', 'User.password') )); - $expected = array( - 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' - ); - $this->assertEquals($expected, $result); + $expected = array( + 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' + ); + $this->assertEquals($expected, $result); - $TestModel = new ModifiedAuthor(); - $result = $TestModel->find('list', array( - 'fields' => array('Author.id', 'Author.user') + $TestModel = new ModifiedAuthor(); + $result = $TestModel->find('list', array( + 'fields' => array('Author.id', 'Author.user') )); - $expected = array( - 1 => 'mariano (CakePHP)', - 2 => 'nate (CakePHP)', - 3 => 'larry (CakePHP)', - 4 => 'garrett (CakePHP)' - ); - $this->assertEquals($expected, $result); + $expected = array( + 1 => 'mariano (CakePHP)', + 2 => 'nate (CakePHP)', + 3 => 'larry (CakePHP)', + 4 => 'garrett (CakePHP)' + ); + $this->assertEquals($expected, $result); - $TestModel = new Article(); - $TestModel->displayField = 'title'; - $result = $TestModel->find('list', array( - 'conditions' => array('User.user' => 'mariano'), - 'recursive' => 0 + $TestModel = new Article(); + $TestModel->displayField = 'title'; + $result = $TestModel->find('list', array( + 'conditions' => array('User.user' => 'mariano'), + 'recursive' => 0 )); - $expected = array( - 1 => 'First Article', - 3 => 'Third Article' - ); - $this->assertEquals($expected, $result); - } + $expected = array( + 1 => 'First Article', + 3 => 'Third Article' + ); + $this->assertEquals($expected, $result); + } -/** - * testFindField method - * - * @return void - */ - public function testFindField() { - $this->loadFixtures('User'); - $TestModel = new User(); + /** + * testFindField method + * + * @return void + */ + public function testFindField() { + $this->loadFixtures('User'); + $TestModel = new User(); - $TestModel->id = 1; - $result = $TestModel->field('user'); - $this->assertEquals('mariano', $result); + $TestModel->id = 1; + $result = $TestModel->field('user'); + $this->assertEquals('mariano', $result); - $result = $TestModel->field('User.user'); - $this->assertEquals('mariano', $result); + $result = $TestModel->field('User.user'); + $this->assertEquals('mariano', $result); - $TestModel->id = false; - $result = $TestModel->field('user', array( - 'user' => 'mariano' + $TestModel->id = false; + $result = $TestModel->field('user', array( + 'user' => 'mariano' )); - $this->assertEquals('mariano', $result); + $this->assertEquals('mariano', $result); - $TestModel->order = null; + $TestModel->order = null; - $result = $TestModel->field('COUNT(*) AS count', true); - $this->assertEquals(4, $result); + $result = $TestModel->field('COUNT(*) AS count', true); + $this->assertEquals(4, $result); - $result = $TestModel->field('COUNT(*)', true); - $this->assertEquals(4, $result); - } + $result = $TestModel->field('COUNT(*)', true); + $this->assertEquals(4, $result); + } -/** - * testFindUnique method - * - * @return void - */ - public function testFindUnique() { - $this->loadFixtures('User'); - $TestModel = new User(); + /** + * testFindUnique method + * + * @return void + */ + public function testFindUnique() { + $this->loadFixtures('User'); + $TestModel = new User(); - $this->assertFalse($TestModel->isUnique(array( - 'user' => 'nate' + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate' ))); - $TestModel->id = 2; - $this->assertTrue($TestModel->isUnique(array( - 'user' => 'nate' + $TestModel->id = 2; + $this->assertTrue($TestModel->isUnique(array( + 'user' => 'nate' ))); - $this->assertFalse($TestModel->isUnique(array( - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ))); - } + } -/** - * test find('count') method - * - * @return void - */ - public function testFindCount() { - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag'); + /** + * test find('count') method + * + * @return void + */ + public function testFindCount() { + $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag'); - $TestModel = new User(); - $this->db->getLog(false, true); - $result = $TestModel->find('count'); - $this->assertEquals(4, $result); + $TestModel = new User(); + $this->db->getLog(false, true); + $result = $TestModel->find('count'); + $this->assertEquals(4, $result); - $this->db->getLog(false, true); - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->order = 'User.id'; - $result = $TestModel->find('count'); - $this->db->fullDebug = $fullDebug; - $this->assertEquals(4, $result); + $this->db->getLog(false, true); + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->order = 'User.id'; + $result = $TestModel->find('count'); + $this->db->fullDebug = $fullDebug; + $this->assertEquals(4, $result); - $log = $this->db->getLog(); - $this->assertTrue(isset($log['log'][0]['query'])); - $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']); + $log = $this->db->getLog(); + $this->assertTrue(isset($log['log'][0]['query'])); + $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']); - $Article = new Article(); - $Article->order = null; - $Article->recursive = -1; + $Article = new Article(); + $Article->order = null; + $Article->recursive = -1; - $expected = count($Article->find('all', array( - 'fields' => array('Article.user_id'), - 'group' => 'Article.user_id') + $expected = count($Article->find('all', array( + 'fields' => array('Article.user_id'), + 'group' => 'Article.user_id') )); - $result = $Article->find('count', array('group' => array('Article.user_id'))); - $this->assertEquals($expected, $result); + $result = $Article->find('count', array('group' => array('Article.user_id'))); + $this->assertEquals($expected, $result); - $expected = count($Article->find('all', array( - 'fields' => array('Article.user_id'), - 'conditions' => array('Article.user_id' => 1), - 'group' => 'Article.user_id') + $expected = count($Article->find('all', array( + 'fields' => array('Article.user_id'), + 'conditions' => array('Article.user_id' => 1), + 'group' => 'Article.user_id') )); - $result = $Article->find('count', array( - 'conditions' => array('Article.user_id' => 1), - 'group' => array('Article.user_id'), + $result = $Article->find('count', array( + 'conditions' => array('Article.user_id' => 1), + 'group' => array('Article.user_id'), )); - $this->assertEquals($expected, $result); - } + $this->assertEquals($expected, $result); + } -/** - * Test that find('first') does not use the id set to the object. - * - * @return void - */ - public function testFindFirstNoIdUsed() { - $this->loadFixtures('Project'); + /** + * Test that find('first') does not use the id set to the object. + * + * @return void + */ + public function testFindFirstNoIdUsed() { + $this->loadFixtures('Project'); - $Project = new Project(); - $Project->id = 3; - $result = $Project->find('first'); + $Project = new Project(); + $Project->id = 3; + $result = $Project->find('first'); - $this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved'); - } + $this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved'); + } -/** - * test find with COUNT(DISTINCT field) - * - * @return void - */ - public function testFindCountDistinct() { - $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.'); - $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.'); + /** + * test find with COUNT(DISTINCT field) + * + * @return void + */ + public function testFindCountDistinct() { + $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.'); + $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.'); - $this->loadFixtures('Project', 'Thread'); - $TestModel = new Project(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); + $this->loadFixtures('Project', 'Thread'); + $TestModel = new Project(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); - $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); - $this->assertEquals(4, $result); - } + $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); + $this->assertEquals(4, $result); + } -/** - * Test find(count) with Db::expression - * - * @return void - */ - public function testFindCountWithDbExpressions() { - $this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.'); + /** + * Test find(count) with Db::expression + * + * @return void + */ + public function testFindCountWithDbExpressions() { + $this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.'); - $this->loadFixtures('Project', 'Thread'); - $db = ConnectionManager::getDataSource('test'); - $TestModel = new Project(); + $this->loadFixtures('Project', 'Thread'); + $db = ConnectionManager::getDataSource('test'); + $TestModel = new Project(); - $result = $TestModel->find('count', array('conditions' => array( - $db->expression('Project.name = \'Project 3\'') + $result = $TestModel->find('count', array('conditions' => array( + $db->expression('Project.name = \'Project 3\'') ))); - $this->assertEquals(1, $result); + $this->assertEquals(1, $result); - $result = $TestModel->find('count', array('conditions' => array( - 'Project.name' => $db->expression('\'Project 3\'') + $result = $TestModel->find('count', array('conditions' => array( + 'Project.name' => $db->expression('\'Project 3\'') ))); - $this->assertEquals(1, $result); - } + $this->assertEquals(1, $result); + } -/** - * testFindMagic method - * - * @return void - */ - public function testFindMagic() { - $this->loadFixtures('User'); - $TestModel = new User(); + /** + * testFindMagic method + * + * @return void + */ + public function testFindMagic() { + $this->loadFixtures('User'); + $TestModel = new User(); - $result = $TestModel->findByUser('mariano'); - $expected = array( + $result = $TestModel->findByUser('mariano'); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )); + $this->assertEquals($expected, $result); + + $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); + $expected = array('User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )); + $this->assertEquals($expected, $result); + } + + /** + * testRead method + * + * @return void + */ + public function testRead() { + $this->loadFixtures('User', 'Article'); + $TestModel = new User(); + + $result = $TestModel->read(); + $this->assertFalse($result); + + $TestModel->id = 2; + $result = $TestModel->read(); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )); + $this->assertEquals($expected, $result); + + $result = $TestModel->read(null, 2); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )); + $this->assertEquals($expected, $result); + + $TestModel->id = 2; + $result = $TestModel->read(array('id', 'user')); + $expected = array('User' => array('id' => '2', 'user' => 'nate')); + $this->assertEquals($expected, $result); + + $result = $TestModel->read('id, user', 2); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + )); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array('hasMany' => array('Article'))); + $this->assertTrue($result); + + $TestModel->id = 1; + $result = $TestModel->read('id, user'); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Article' => array( + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + $this->assertEquals($expected, $result); + } + + /** + * testRecursiveRead method + * + * @return void + */ + public function testRecursiveRead() { + $this->loadFixtures( + 'User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Featured', 'ArticleFeatured' + ); + $TestModel = new User(); + + $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); + $this->assertTrue($result); + + $TestModel->recursive = 0; + $result = $TestModel->read('id, user', 1); + $expected = array( + 'User' => array('id' => '1', 'user' => 'mariano'), + ); + $this->assertEquals($expected, $result); + + $TestModel->recursive = 1; + $result = $TestModel->read('id, user', 1); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Article' => array( + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + $this->assertEquals($expected, $result); + + $TestModel->recursive = 2; + $result = $TestModel->read('id, user', 3); + $expected = array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Article' => array( + array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))))); + $this->assertEquals($expected, $result); + } + + public function testRecursiveFindAll() { + $this->loadFixtures( + 'User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'ArticleFeaturedsTags', 'Featured', 'Category' + ); + $TestModel = new Article(); + + $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); + $expected = array( + array( + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array(), + 'Tag' => array() + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 + )); + + $expected = array( + array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )); - $this->assertEquals($expected, $result); + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Attachment' => array() + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + )))); - $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); - $expected = array('User' => array( + $this->assertEquals($expected, $result); + + $Featured = new Featured(); + + $Featured->recursive = 2; + $Featured->bindModel(array( + 'belongsTo' => array( + 'ArticleFeatured' => array( + 'conditions' => "ArticleFeatured.published = 'Y'", + 'fields' => 'id, title, user_id, published' + ) + ) + )); + + $Featured->ArticleFeatured->unbindModel(array( + 'hasMany' => array('Attachment', 'Comment'), + 'hasAndBelongsToMany' => array('Tag')) + ); + + $orderBy = 'ArticleFeatured.id ASC'; + $result = $Featured->find('all', array( + 'order' => $orderBy, 'limit' => 3 + )); + + $expected = array( + array( + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '1', + 'title' => 'First Article', + 'user_id' => '1', + 'published' => 'Y', + 'User' => array( 'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' + ), + 'Category' => array(), + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + )), + array( + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '2', + 'title' => 'Second Article', + 'user_id' => '3', + 'published' => 'Y', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Category' => array(), + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))); + $this->assertEquals($expected, $result); + } + + /** + * testRecursiveFindAllWithLimit method + * + * @return void + */ + public function testRecursiveFindAllWithLimit() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); + $TestModel = new Article(); + + $TestModel->hasMany['Comment']['limit'] = 2; + + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 1) )); - $this->assertEquals($expected, $result); - } + $expected = array( + array( + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array(), + 'Tag' => array() + ) + ); + $this->assertEquals($expected, $result); -/** - * testRead method - * - * @return void - */ - public function testRead() { - $this->loadFixtures('User', 'Article'); - $TestModel = new User(); + $TestModel->hasMany['Comment']['limit'] = 1; - $result = $TestModel->read(); - $this->assertFalse($result); - - $TestModel->id = 2; - $result = $TestModel->read(); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 )); - $this->assertEquals($expected, $result); - - $result = $TestModel->read(null, 2); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->read(array('id', 'user')); - $expected = array('User' => array('id' => '2', 'user' => 'nate')); - $this->assertEquals($expected, $result); - - $result = $TestModel->read('id, user', 2); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - )); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array('hasMany' => array('Article'))); - $this->assertTrue($result); - - $TestModel->id = 1; - $result = $TestModel->read('id, user'); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), + $expected = array( + array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', 'Article' => array( - array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); - $this->assertEquals($expected, $result); - } - -/** - * testRecursiveRead method - * - * @return void - */ - public function testRecursiveRead() { - $this->loadFixtures( - 'User', - 'Article', - 'Comment', - 'Tag', - 'ArticlesTag', - 'Featured', - 'ArticleFeatured' - ); - $TestModel = new User(); - - $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); - $this->assertTrue($result); - - $TestModel->recursive = 0; - $result = $TestModel->read('id, user', 1); - $expected = array( - 'User' => array('id' => '1', 'user' => 'mariano'), - ); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 1; - $result = $TestModel->read('id, user', 1); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' ), - 'Article' => array( - array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 2; - $result = $TestModel->read('id, user', 3); - $expected = array( 'User' => array( - 'id' => '3', - 'user' => 'larry' + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' ), - 'Article' => array( - array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31', - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))))); - $this->assertEquals($expected, $result); - } - - public function testRecursiveFindAll() { - $this->loadFixtures( - 'User', - 'Article', - 'Comment', - 'Tag', - 'ArticlesTag', - 'Attachment', - 'ArticleFeatured', - 'ArticleFeaturedsTags', - 'Featured', - 'Category' - ); - $TestModel = new Article(); - - $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array(), - 'Tag' => array() + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' ) - ); - $this->assertEquals($expected, $result); + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) + ) + ) + ); + $this->assertEquals($expected, $result); + } - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 3), - 'limit' => 1, - 'recursive' => 2 + /** + * Testing availability of $this->findQueryType in Model callbacks + * + * @return void + */ + public function testFindQueryTypeInCallbacks() { + $this->loadFixtures('Comment'); + $Comment = new AgainModifiedComment(); + $comments = $Comment->find('all'); + $this->assertEquals('all', $comments[0]['Comment']['querytype']); + $comments = $Comment->find('first'); + $this->assertEquals('first', $comments['Comment']['querytype']); + } + + /** + * testVirtualFields() + * + * Test correct fetching of virtual fields + * currently is not possible to do Relation.virtualField + * + * @return void + */ + public function testVirtualFields() { + $this->loadFixtures('Post', 'Author'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('two' => "1 + 1"); + $result = $Post->find('first'); + $this->assertEquals(2, $result['Post']['two']); + + // SQL Server does not support operators in expressions + if (!($this->db instanceof Sqlserver)) { + $Post->Author->virtualFields = array('false' => '1 = 2'); + $result = $Post->find('first'); + $this->assertEquals(2, $result['Post']['two']); + $this->assertFalse((bool) $result['Author']['false']); + } + + $result = $Post->find('first', array('fields' => array('author_id'))); + $this->assertFalse(isset($result['Post']['two'])); + $this->assertFalse(isset($result['Author']['false'])); + + $result = $Post->find('first', array('fields' => array('author_id', 'two'))); + $this->assertEquals(2, $result['Post']['two']); + $this->assertFalse(isset($result['Author']['false'])); + + $result = $Post->find('first', array('fields' => array('two'))); + $this->assertEquals(2, $result['Post']['two']); + + $Post->id = 1; + $result = $Post->field('two'); + $this->assertEquals(2, $result); + + $result = $Post->find('first', array( + 'conditions' => array('two' => 2), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['two']); + + $result = $Post->find('first', array( + 'conditions' => array('two <' => 3), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['two']); + + $result = $Post->find('first', array( + 'conditions' => array('NOT' => array('two >' => 3)), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['two']); + + $dbo = $Post->getDataSource(); + $Post->virtualFields = array('other_field' => 'Post.id + 1'); + $result = $Post->find('first', array( + 'conditions' => array('other_field' => 3), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['id']); + + $Post->order = null; + + $Post->virtualFields = array('other_field' => 'Post.id + 1'); + $result = $Post->find('all', array( + 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) + )); + $this->assertEquals(4, $result[0][0]['other_field']); + + ClassRegistry::flush(); + $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing')); + $Writing->virtualFields = array('two' => "1 + 1"); + $result = $Writing->find('first'); + $this->assertEquals(2, $result['Writing']['two']); + + $Post->create(); + $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); + $result = $Post->field('other_field'); + $this->assertEquals(4, $result); + } + + /** + * testVirtualFieldsOrder() + * + * Test correct order on virtual fields + * + * @return void + */ + public function testVirtualFieldsOrder() { + $this->loadFixtures('Post', 'Author'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('other_field' => '10 - Post.id'); + $result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC'))); + $expected = array( + '3' => 'Third Post', + '2' => 'Second Post', + '1' => 'First Post' + ); + $this->assertEquals($expected, $result); + + $result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC'))); + $expected = array( + '1' => 'First Post', + '2' => 'Second Post', + '3' => 'Third Post' + ); + $this->assertEquals($expected, $result); + + $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id'); + $result = $Post->find('all', array( + 'order' => array('Post.id' => 'ASC') + )); + $result = Hash::extract($result, '{n}.Author.joined'); + $expected = array(1, 6, 3); + $this->assertEquals($expected, $result); + + $result = $Post->find('all', array('order' => array('Author.joined' => 'ASC'))); + $result = Hash::extract($result, '{n}.Author.joined'); + $expected = array(1, 3, 6); + $this->assertEquals($expected, $result); + + $result = $Post->find('all', array('order' => array('Author.joined' => 'DESC'))); + $result = Hash::extract($result, '{n}.Author.joined'); + $expected = array(6, 3, 1); + $this->assertEquals($expected, $result); + } + + /** + * testVirtualFieldsMysql() + * + * Test correct fetching of virtual fields + * currently is not possible to do Relation.virtualField + * + */ + public function testVirtualFieldsMysql() { + $this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFields test only compatible with Mysql.'); + + $this->loadFixtures('Post', 'Author'); + $Post = ClassRegistry::init('Post'); + + $Post->create(); + $Post->virtualFields = array( + 'low_title' => 'lower(Post.title)', + 'unique_test_field' => 'COUNT(Post.id)' + ); + + $expectation = array( + 'Post' => array( + 'low_title' => 'first post', + 'unique_test_field' => 1 + ) + ); + + $result = $Post->find('first', array( + 'fields' => array_keys($Post->virtualFields), + 'group' => array('low_title') )); - $expected = array( - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Attachment' => array( - 'id' => '1', - 'comment_id' => 5, - 'attachment' => 'attachment.zip', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - ), - 'Attachment' => array() - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - )))); + $this->assertEquals($expectation, $result); - $this->assertEquals($expected, $result); + $Author = ClassRegistry::init('Author'); + $Author->virtualFields = array( + 'full_name' => 'CONCAT(Author.user, " ", Author.id)' + ); - $Featured = new Featured(); + $result = $Author->find('first', array( + 'conditions' => array('Author.user' => 'mariano'), + 'fields' => array('Author.password', 'Author.full_name'), + 'recursive' => -1 + )); + $this->assertTrue(isset($result['Author']['full_name'])); - $Featured->recursive = 2; - $Featured->bindModel(array( - 'belongsTo' => array( - 'ArticleFeatured' => array( - 'conditions' => "ArticleFeatured.published = 'Y'", - 'fields' => 'id, title, user_id, published' - ) + $result = $Author->find('first', array( + 'conditions' => array('Author.user' => 'mariano'), + 'fields' => array('Author.full_name', 'Author.password'), + 'recursive' => -1 + )); + $this->assertTrue(isset($result['Author']['full_name'])); + } + + /** + * test that virtual fields work when they don't contain functions. + * + * @return void + */ + public function testVirtualFieldAsAString() { + $this->loadFixtures('Post', 'Author'); + $Post = new Post(); + $Post->virtualFields = array( + 'writer' => 'Author.user' + ); + $result = $Post->find('first'); + $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s'); + } + + /** + * test that isVirtualField will accept both aliased and non aliased fieldnames + * + * @return void + */ + public function testIsVirtualField() { + $this->loadFixtures('Post'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); + + $this->assertTrue($Post->isVirtualField('other_field')); + $this->assertTrue($Post->isVirtualField('Post.other_field')); + $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.'); + $this->assertFalse($Post->isVirtualField('id')); + $this->assertFalse($Post->isVirtualField('Post.id')); + $this->assertFalse($Post->isVirtualField(array())); + } + + /** + * test that getting virtual fields works with and without model alias attached + * + * @return void + */ + public function testGetVirtualField() { + $this->loadFixtures('Post'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); + + $this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']); + $this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']); + } + + /** + * test that checks for error when NOT condition passed in key and a 1 element array value + * + * @return void + */ + public function testNotInArrayWithOneValue() { + $this->loadFixtures('Article'); + $Article = new Article(); + $Article->recursive = -1; + + $result = $Article->find( + 'all', array( + 'conditions' => array( + 'Article.id NOT' => array(1) + ) + ) + ); + $this->assertTrue(is_array($result) && !empty($result)); + } + + /** + * test custom find method + * + * @return void + */ + public function testfindCustom() { + $this->loadFixtures('Article'); + $Article = new CustomArticle(); + $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N'); + $Article->create($data); + $Article->save(null, false); + $this->assertEquals(4, $Article->id); + + $result = $Article->find('published'); + $this->assertEquals(3, count($result)); + + $result = $Article->find('unPublished'); + $this->assertEquals(1, count($result)); + } + + /** + * test after find callback on related model + * + * @return void + */ + public function testRelatedAfterFindCallback() { + $this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation'); + $ModelWithRelations = new ModelWithRelations(); + +// belongsTo Test + $ModelWithRelations->bindModel(array( + 'belongsTo' => array( + 'BelongsTo' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'related_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'BelongsTo' => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'BelongsTo' => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail'); + +// hasOne test + $ModelWithRelations->bindModel(array( + 'hasOne' => array( + 'HasOne' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'primary_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasOne' => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasOne' => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasOne afterFind callback fail'); + +// hasMany test + $ModelWithRelations->bindModel(array( + 'hasMany' => array( + 'HasMany' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'primary_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasMany' => array( + (int) 0 => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasMany' => array( + (int) 0 => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasMany afterFind callback fail'); + +// hasAndBelongsToMany test + $ModelWithRelations->bindModel(array( + 'hasAndBelongsToMany' => array( + 'HasAndBelongsToMany' => array( + 'className' => 'ModelRelated', + 'with' => 'ModelHabtmRelation', + 'foreignKey' => 'primary_id', + 'associationForeignKey' => 'related_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasAndBelongsToMany' => array( + (int) 0 => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1', + 'ModelHabtmRelation' => array( + 'id' => '1', + 'primary_id' => '1', + 'related_id' => '1' ) - )); - - $Featured->ArticleFeatured->unbindModel(array( - 'hasMany' => array('Attachment', 'Comment'), - 'hasAndBelongsToMany' => array('Tag')) - ); - - $orderBy = 'ArticleFeatured.id ASC'; - $result = $Featured->find('all', array( - 'order' => $orderBy, 'limit' => 3 - )); - - $expected = array( - array( - 'Featured' => array( - 'id' => '1', - 'article_featured_id' => '1', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'ArticleFeatured' => array( - 'id' => '1', - 'title' => 'First Article', - 'user_id' => '1', - 'published' => 'Y', - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Category' => array(), - 'Featured' => array( - 'id' => '1', - 'article_featured_id' => '1', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - )), - array( - 'Featured' => array( - 'id' => '2', - 'article_featured_id' => '2', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'ArticleFeatured' => array( - 'id' => '2', - 'title' => 'Second Article', - 'user_id' => '3', - 'published' => 'Y', - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Category' => array(), - 'Featured' => array( - 'id' => '2', - 'article_featured_id' => '2', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))); - $this->assertEquals($expected, $result); - } - -/** - * testRecursiveFindAllWithLimit method - * - * @return void - */ - public function testRecursiveFindAllWithLimit() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); - $TestModel = new Article(); - - $TestModel->hasMany['Comment']['limit'] = 2; - - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 1) - )); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array(), - 'Tag' => array() + ), + (int) 1 => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2', + 'ModelHabtmRelation' => array( + 'id' => '2', + 'primary_id' => '1', + 'related_id' => '2' ) - ); - $this->assertEquals($expected, $result); - - $TestModel->hasMany['Comment']['limit'] = 1; - - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 3), - 'limit' => 1, - 'recursive' => 2 - )); - $expected = array( - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Attachment' => array( - 'id' => '1', - 'comment_id' => 5, - 'attachment' => 'attachment.zip', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ) - ) + ) + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasAndBelongsToMany' => array( + (int) 0 => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1', + 'ModelHabtmRelation' => array( + 'id' => '3', + 'primary_id' => '2', + 'related_id' => '1' ) - ); - $this->assertEquals($expected, $result); - } - -/** - * Testing availability of $this->findQueryType in Model callbacks - * - * @return void - */ - public function testFindQueryTypeInCallbacks() { - $this->loadFixtures('Comment'); - $Comment = new AgainModifiedComment(); - $comments = $Comment->find('all'); - $this->assertEquals('all', $comments[0]['Comment']['querytype']); - $comments = $Comment->find('first'); - $this->assertEquals('first', $comments['Comment']['querytype']); - } - -/** - * testVirtualFields() - * - * Test correct fetching of virtual fields - * currently is not possible to do Relation.virtualField - * - * @return void - */ - public function testVirtualFields() { - $this->loadFixtures('Post', 'Author'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('two' => "1 + 1"); - $result = $Post->find('first'); - $this->assertEquals(2, $result['Post']['two']); - - // SQL Server does not support operators in expressions - if (!($this->db instanceof Sqlserver)) { - $Post->Author->virtualFields = array('false' => '1 = 2'); - $result = $Post->find('first'); - $this->assertEquals(2, $result['Post']['two']); - $this->assertFalse((bool)$result['Author']['false']); - } - - $result = $Post->find('first', array('fields' => array('author_id'))); - $this->assertFalse(isset($result['Post']['two'])); - $this->assertFalse(isset($result['Author']['false'])); - - $result = $Post->find('first', array('fields' => array('author_id', 'two'))); - $this->assertEquals(2, $result['Post']['two']); - $this->assertFalse(isset($result['Author']['false'])); - - $result = $Post->find('first', array('fields' => array('two'))); - $this->assertEquals(2, $result['Post']['two']); - - $Post->id = 1; - $result = $Post->field('two'); - $this->assertEquals(2, $result); - - $result = $Post->find('first', array( - 'conditions' => array('two' => 2), - 'limit' => 1 - )); - $this->assertEquals(2, $result['Post']['two']); - - $result = $Post->find('first', array( - 'conditions' => array('two <' => 3), - 'limit' => 1 - )); - $this->assertEquals(2, $result['Post']['two']); - - $result = $Post->find('first', array( - 'conditions' => array('NOT' => array('two >' => 3)), - 'limit' => 1 - )); - $this->assertEquals(2, $result['Post']['two']); - - $dbo = $Post->getDataSource(); - $Post->virtualFields = array('other_field' => 'Post.id + 1'); - $result = $Post->find('first', array( - 'conditions' => array('other_field' => 3), - 'limit' => 1 - )); - $this->assertEquals(2, $result['Post']['id']); - - $Post->order = null; - - $Post->virtualFields = array('other_field' => 'Post.id + 1'); - $result = $Post->find('all', array( - 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) - )); - $this->assertEquals(4, $result[0][0]['other_field']); - - ClassRegistry::flush(); - $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing')); - $Writing->virtualFields = array('two' => "1 + 1"); - $result = $Writing->find('first'); - $this->assertEquals(2, $result['Writing']['two']); - - $Post->create(); - $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); - $result = $Post->field('other_field'); - $this->assertEquals(4, $result); - } - -/** - * testVirtualFieldsOrder() - * - * Test correct order on virtual fields - * - * @return void - */ - public function testVirtualFieldsOrder() { - $this->loadFixtures('Post', 'Author'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('other_field' => '10 - Post.id'); - $result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC'))); - $expected = array( - '3' => 'Third Post', - '2' => 'Second Post', - '1' => 'First Post' - ); - $this->assertEquals($expected, $result); - - $result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC'))); - $expected = array( - '1' => 'First Post', - '2' => 'Second Post', - '3' => 'Third Post' - ); - $this->assertEquals($expected, $result); - - $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id'); - $result = $Post->find('all', array( - 'order' => array('Post.id' => 'ASC') - )); - $result = Hash::extract($result, '{n}.Author.joined'); - $expected = array(1, 6, 3); - $this->assertEquals($expected, $result); - - $result = $Post->find('all', array('order' => array('Author.joined' => 'ASC'))); - $result = Hash::extract($result, '{n}.Author.joined'); - $expected = array(1, 3, 6); - $this->assertEquals($expected, $result); - - $result = $Post->find('all', array('order' => array('Author.joined' => 'DESC'))); - $result = Hash::extract($result, '{n}.Author.joined'); - $expected = array(6, 3, 1); - $this->assertEquals($expected, $result); - } - -/** - * testVirtualFieldsMysql() - * - * Test correct fetching of virtual fields - * currently is not possible to do Relation.virtualField - * - */ - public function testVirtualFieldsMysql() { - $this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFields test only compatible with Mysql.'); - - $this->loadFixtures('Post', 'Author'); - $Post = ClassRegistry::init('Post'); - - $Post->create(); - $Post->virtualFields = array( - 'low_title' => 'lower(Post.title)', - 'unique_test_field' => 'COUNT(Post.id)' - ); - - $expectation = array( - 'Post' => array( - 'low_title' => 'first post', - 'unique_test_field' => 1 + ), + (int) 1 => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2', + 'ModelHabtmRelation' => array( + 'id' => '4', + 'primary_id' => '2', + 'related_id' => '2' ) - ); - - $result = $Post->find('first', array( - 'fields' => array_keys($Post->virtualFields), - 'group' => array('low_title') - )); - - $this->assertEquals($expectation, $result); - - $Author = ClassRegistry::init('Author'); - $Author->virtualFields = array( - 'full_name' => 'CONCAT(Author.user, " ", Author.id)' - ); - - $result = $Author->find('first', array( - 'conditions' => array('Author.user' => 'mariano'), - 'fields' => array('Author.password', 'Author.full_name'), - 'recursive' => -1 - )); - $this->assertTrue(isset($result['Author']['full_name'])); - - $result = $Author->find('first', array( - 'conditions' => array('Author.user' => 'mariano'), - 'fields' => array('Author.full_name', 'Author.password'), - 'recursive' => -1 - )); - $this->assertTrue(isset($result['Author']['full_name'])); - } - -/** - * test that virtual fields work when they don't contain functions. - * - * @return void - */ - public function testVirtualFieldAsAString() { - $this->loadFixtures('Post', 'Author'); - $Post = new Post(); - $Post->virtualFields = array( - 'writer' => 'Author.user' - ); - $result = $Post->find('first'); - $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s'); - } - -/** - * test that isVirtualField will accept both aliased and non aliased fieldnames - * - * @return void - */ - public function testIsVirtualField() { - $this->loadFixtures('Post'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); - - $this->assertTrue($Post->isVirtualField('other_field')); - $this->assertTrue($Post->isVirtualField('Post.other_field')); - $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.'); - $this->assertFalse($Post->isVirtualField('id')); - $this->assertFalse($Post->isVirtualField('Post.id')); - $this->assertFalse($Post->isVirtualField(array())); - } - -/** - * test that getting virtual fields works with and without model alias attached - * - * @return void - */ - public function testGetVirtualField() { - $this->loadFixtures('Post'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); - - $this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']); - $this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']); - } - -/** - * test that checks for error when NOT condition passed in key and a 1 element array value - * - * @return void - */ - public function testNotInArrayWithOneValue() { - $this->loadFixtures('Article'); - $Article = new Article(); - $Article->recursive = -1; - - $result = $Article->find( - 'all', - array( - 'conditions' => array( - 'Article.id NOT' => array(1) - ) - ) - ); - $this->assertTrue(is_array($result) && !empty($result)); - } - -/** - * test custom find method - * - * @return void - */ - public function testfindCustom() { - $this->loadFixtures('Article'); - $Article = new CustomArticle(); - $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N'); - $Article->create($data); - $Article->save(null, false); - $this->assertEquals(4, $Article->id); - - $result = $Article->find('published'); - $this->assertEquals(3, count($result)); - - $result = $Article->find('unPublished'); - $this->assertEquals(1, count($result)); - } + ) + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasAndBelongsToMany afterFind callback fail'); + } } diff --git a/lib/Cake/Test/Case/Model/ModelTestBase.php b/lib/Cake/Test/Case/Model/ModelTestBase.php index 16bffd8b4..6f444e338 100644 --- a/lib/Cake/Test/Case/Model/ModelTestBase.php +++ b/lib/Cake/Test/Case/Model/ModelTestBase.php @@ -1,4 +1,5 @@ debug = Configure::read('debug'); - } + /** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + $this->debug = Configure::read('debug'); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() { + parent::tearDown(); + Configure::write('debug', $this->debug); + ClassRegistry::flush(); + } -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - parent::tearDown(); - Configure::write('debug', $this->debug); - ClassRegistry::flush(); - } } diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index 1f6c8799b..85d474d33 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -1,4 +1,5 @@ true); + /** + * findMethods property + * + * @var array + */ + public $findMethods = array('published' => true); -/** - * useDbConfig property - * - * @var array - */ - public $useDbConfig = 'test'; + /** + * useDbConfig property + * + * @var array + */ + public $useDbConfig = 'test'; -/** - * _findPublished custom find - * - * @return array - */ - protected function _findPublished($state, $query, $results = array()) { - if ($state === 'before') { - $query['conditions']['published'] = 'Y'; - return $query; - } - return $results; + /** + * _findPublished custom find + * + * @return array + */ + protected function _findPublished($state, $query, $results = array()) { + if ($state === 'before') { + $query['conditions']['published'] = 'Y'; + return $query; } + return $results; + } } @@ -65,33 +65,33 @@ class AppModel extends Model { */ class Test extends CakeTestModel { -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * name property - * - * @var string - */ - public $name = 'Test'; + /** + * name property + * + * @var string + */ + public $name = 'Test'; -/** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); + /** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } @@ -102,33 +102,34 @@ class Test extends CakeTestModel { */ class TestAlias extends CakeTestModel { -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * name property - * - * @var string - */ - public $name = 'TestAlias'; + /** + * name property + * + * @var string + */ + public $name = 'TestAlias'; + + /** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); -/** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); } /** @@ -138,56 +139,56 @@ class TestAlias extends CakeTestModel { */ class TestValidate extends CakeTestModel { -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * name property - * - * @var string - */ - public $name = 'TestValidate'; + /** + * name property + * + * @var string + */ + public $name = 'TestValidate'; -/** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'title' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'body' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => ''), - 'number' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'modified' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); + /** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'title' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'body' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => ''), + 'number' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'modified' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); -/** - * validateNumber method - * - * @param mixed $value - * @param mixed $options - * @return void - */ - public function validateNumber($value, $options) { - $options = array_merge(array('min' => 0, 'max' => 100), $options); - $valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']); - return $valid; - } + /** + * validateNumber method + * + * @param mixed $value + * @param mixed $options + * @return void + */ + public function validateNumber($value, $options) { + $options = array_merge(array('min' => 0, 'max' => 100), $options); + $valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']); + return $valid; + } -/** - * validateTitle method - * - * @param mixed $value - * @return void - */ - public function validateTitle($value) { - return (!empty($value) && strpos(strtolower($value['title']), 'title-') === 0); - } + /** + * validateTitle method + * + * @param mixed $value + * @return void + */ + public function validateTitle($value) { + return (!empty($value) && strpos(strtolower($value['title']), 'title-') === 0); + } } @@ -198,34 +199,34 @@ class TestValidate extends CakeTestModel { */ class User extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'User'; + /** + * name property + * + * @var string + */ + public $name = 'User'; -/** - * validate property - * - * @var array - */ - public $validate = array('user' => 'notEmpty', 'password' => 'notEmpty'); + /** + * validate property + * + * @var array + */ + public $validate = array('user' => 'notEmpty', 'password' => 'notEmpty'); -/** - * beforeFind() callback used to run ContainableBehaviorTest::testLazyLoad() - * - * @return bool - * @throws Exception - */ - public function beforeFind($queryData) { - if (!empty($queryData['lazyLoad'])) { - if (!isset($this->Article, $this->Comment, $this->ArticleFeatured)) { - throw new Exception('Unavailable associations'); - } - } - return true; + /** + * beforeFind() callback used to run ContainableBehaviorTest::testLazyLoad() + * + * @return bool + * @throws Exception + */ + public function beforeFind($queryData) { + if (!empty($queryData['lazyLoad'])) { + if (!isset($this->Article, $this->Comment, $this->ArticleFeatured)) { + throw new Exception('Unavailable associations'); + } } + return true; + } } @@ -236,73 +237,73 @@ class User extends CakeTestModel { */ class Article extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Article'; + /** + * name property + * + * @var string + */ + public $name = 'Article'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Comment' => array('dependent' => true)); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Comment' => array('dependent' => true)); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Tag'); + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Tag'); -/** - * validate property - * - * @var array - */ - public $validate = array( - 'user_id' => 'numeric', - 'title' => array('required' => false, 'rule' => 'notEmpty'), - 'body' => array('required' => false, 'rule' => 'notEmpty'), - ); + /** + * validate property + * + * @var array + */ + public $validate = array( + 'user_id' => 'numeric', + 'title' => array('required' => false, 'rule' => 'notEmpty'), + 'body' => array('required' => false, 'rule' => 'notEmpty'), + ); -/** - * beforeSaveReturn property - * - * @var bool true - */ - public $beforeSaveReturn = true; + /** + * beforeSaveReturn property + * + * @var bool true + */ + public $beforeSaveReturn = true; -/** - * beforeSave method - * - * @return void - */ - public function beforeSave($options = array()) { - return $this->beforeSaveReturn; - } - -/** - * titleDuplicate method - * - * @param string $title - * @return void - */ - public static function titleDuplicate($title) { - if ($title === 'My Article Title') { - return false; - } - return true; + /** + * beforeSave method + * + * @return void + */ + public function beforeSave($options = array()) { + return $this->beforeSaveReturn; + } + + /** + * titleDuplicate method + * + * @param string $title + * @return void + */ + public static function titleDuplicate($title) { + if ($title === 'My Article Title') { + return false; } + return true; + } } @@ -314,15 +315,14 @@ class Article extends CakeTestModel { */ class BeforeDeleteComment extends CakeTestModel { - public $name = 'BeforeDeleteComment'; + public $name = 'BeforeDeleteComment'; + public $useTable = 'comments'; - public $useTable = 'comments'; - - public function beforeDelete($cascade = true) { - $db = $this->getDataSource(); - $db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3))); - return true; - } + public function beforeDelete($cascade = true) { + $db = $this->getDataSource(); + $db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3))); + return true; + } } @@ -333,19 +333,19 @@ class BeforeDeleteComment extends CakeTestModel { */ class NumericArticle extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'NumericArticle'; + /** + * name property + * + * @var string + */ + public $name = 'NumericArticle'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'numeric_articles'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'numeric_articles'; } @@ -356,26 +356,26 @@ class NumericArticle extends CakeTestModel { */ class Article10 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Article10'; + /** + * name property + * + * @var string + */ + public $name = 'Article10'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'articles'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'articles'; -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Comment' => array('dependent' => true, 'exclusive' => true)); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Comment' => array('dependent' => true, 'exclusive' => true)); } @@ -386,47 +386,47 @@ class Article10 extends CakeTestModel { */ class ArticleFeatured extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ArticleFeatured'; + /** + * name property + * + * @var string + */ + public $name = 'ArticleFeatured'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User', 'Category'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User', 'Category'); -/** - * hasOne property - * - * @var array - */ - public $hasOne = array('Featured'); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array('Featured'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Comment' => array('className' => 'Comment', 'dependent' => true)); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Comment' => array('className' => 'Comment', 'dependent' => true)); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Tag'); + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Tag'); -/** - * validate property - * - * @var array - */ - public $validate = array('user_id' => 'numeric', 'title' => 'notEmpty', 'body' => 'notEmpty'); + /** + * validate property + * + * @var array + */ + public $validate = array('user_id' => 'numeric', 'title' => 'notEmpty', 'body' => 'notEmpty'); } @@ -437,19 +437,20 @@ class ArticleFeatured extends CakeTestModel { */ class Featured extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Featured'; + /** + * name property + * + * @var string + */ + public $name = 'Featured'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('ArticleFeatured', 'Category'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('ArticleFeatured', 'Category'); } /** @@ -459,12 +460,13 @@ class Featured extends CakeTestModel { */ class Tag extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Tag'; + /** + * name property + * + * @var string + */ + public $name = 'Tag'; + } /** @@ -474,12 +476,13 @@ class Tag extends CakeTestModel { */ class ArticlesTag extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ArticlesTag'; + /** + * name property + * + * @var string + */ + public $name = 'ArticlesTag'; + } /** @@ -489,12 +492,13 @@ class ArticlesTag extends CakeTestModel { */ class ArticleFeaturedsTag extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ArticleFeaturedsTag'; + /** + * name property + * + * @var string + */ + public $name = 'ArticleFeaturedsTag'; + } /** @@ -504,26 +508,27 @@ class ArticleFeaturedsTag extends CakeTestModel { */ class Comment extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Comment'; + /** + * name property + * + * @var string + */ + public $name = 'Comment'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Article', 'User'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Article', 'User'); + + /** + * hasOne property + * + * @var array + */ + public $hasOne = array('Attachment' => array('dependent' => true)); -/** - * hasOne property - * - * @var array - */ - public $hasOne = array('Attachment' => array('dependent' => true)); } /** @@ -533,48 +538,48 @@ class Comment extends CakeTestModel { */ class ModifiedComment extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Comment'; + /** + * name property + * + * @var string + */ + public $name = 'Comment'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'comments'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'comments'; -/** - * Property used to toggle filtering of results - * - * @var boolean - */ - public $remove = false; + /** + * Property used to toggle filtering of results + * + * @var boolean + */ + public $remove = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Article'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Article'); -/** - * afterFind callback - * - * @return void - */ - public function afterFind($results, $primary = false) { - if (isset($results[0])) { - $results[0]['Comment']['callback'] = 'Fire'; - } - if ($this->remove) { - return array(); - } - return $results; + /** + * afterFind callback + * + * @return void + */ + public function afterFind($results, $primary = false) { + if (isset($results[0])) { + $results[0]['Comment']['callback'] = 'Fire'; } + if ($this->remove) { + return array(); + } + return $results; + } } @@ -585,38 +590,38 @@ class ModifiedComment extends CakeTestModel { */ class AgainModifiedComment extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Comment'; + /** + * name property + * + * @var string + */ + public $name = 'Comment'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'comments'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'comments'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Article'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Article'); -/** - * afterFind callback - * - * @return void - */ - public function afterFind($results, $primary = false) { - if (isset($results[0])) { - $results[0]['Comment']['querytype'] = $this->findQueryType; - } - return $results; + /** + * afterFind callback + * + * @return void + */ + public function afterFind($results, $primary = false) { + if (isset($results[0])) { + $results[0]['Comment']['querytype'] = $this->findQueryType; } + return $results; + } } @@ -627,14 +632,15 @@ class AgainModifiedComment extends CakeTestModel { */ class MergeVarPluginAppModel extends AppModel { -/** - * actsAs parameter - * - * @var array - */ - public $actsAs = array( - 'Containable' - ); + /** + * actsAs parameter + * + * @var array + */ + public $actsAs = array( + 'Containable' + ); + } /** @@ -644,21 +650,22 @@ class MergeVarPluginAppModel extends AppModel { */ class MergeVarPluginPost extends MergeVarPluginAppModel { -/** - * actsAs parameter - * - * @var array - */ - public $actsAs = array( - 'Tree' - ); + /** + * actsAs parameter + * + * @var array + */ + public $actsAs = array( + 'Tree' + ); + + /** + * useTable parameter + * + * @var string + */ + public $useTable = 'posts'; -/** - * useTable parameter - * - * @var string - */ - public $useTable = 'posts'; } /** @@ -668,21 +675,22 @@ class MergeVarPluginPost extends MergeVarPluginAppModel { */ class MergeVarPluginComment extends MergeVarPluginAppModel { -/** - * actsAs parameter - * - * @var array - */ - public $actsAs = array( - 'Containable' => array('some_settings') - ); + /** + * actsAs parameter + * + * @var array + */ + public $actsAs = array( + 'Containable' => array('some_settings') + ); + + /** + * useTable parameter + * + * @var string + */ + public $useTable = 'comments'; -/** - * useTable parameter - * - * @var string - */ - public $useTable = 'comments'; } /** @@ -692,19 +700,20 @@ class MergeVarPluginComment extends MergeVarPluginAppModel { */ class Attachment extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Attachment'; + /** + * name property + * + * @var string + */ + public $name = 'Attachment'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Comment'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Comment'); } /** @@ -714,31 +723,31 @@ class Attachment extends CakeTestModel { */ class ModifiedAttachment extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ModifiedAttachment'; + /** + * name property + * + * @var string + */ + public $name = 'ModifiedAttachment'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'attachments'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'attachments'; -/** - * afterFind callback - * - * @return void - */ - public function afterFind($results, $primary = false) { - if (isset($results['id'])) { - $results['callback'] = 'Fired'; - } - return $results; + /** + * afterFind callback + * + * @return void + */ + public function afterFind($results, $primary = false) { + if (isset($results['id'])) { + $results['callback'] = 'Fired'; } + return $results; + } } @@ -749,12 +758,13 @@ class ModifiedAttachment extends CakeTestModel { */ class Category extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Category'; + /** + * name property + * + * @var string + */ + public $name = 'Category'; + } /** @@ -764,19 +774,20 @@ class Category extends CakeTestModel { */ class CategoryThread extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'CategoryThread'; + /** + * name property + * + * @var string + */ + public $name = 'CategoryThread'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('ParentCategory' => array('className' => 'CategoryThread', 'foreignKey' => 'parent_id')); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('ParentCategory' => array('className' => 'CategoryThread', 'foreignKey' => 'parent_id')); } /** @@ -786,40 +797,41 @@ class CategoryThread extends CakeTestModel { */ class Apple extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Apple'; + /** + * name property + * + * @var string + */ + public $name = 'Apple'; -/** - * validate property - * - * @var array - */ - public $validate = array('name' => 'notEmpty'); + /** + * validate property + * + * @var array + */ + public $validate = array('name' => 'notEmpty'); -/** - * hasOne property - * - * @var array - */ - public $hasOne = array('Sample'); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array('Sample'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Child' => array('className' => 'Apple', 'dependent' => true)); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Child' => array('className' => 'Apple', 'dependent' => true)); + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Parent' => array('className' => 'Apple', 'foreignKey' => 'apple_id')); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Parent' => array('className' => 'Apple', 'foreignKey' => 'apple_id')); } /** @@ -829,19 +841,20 @@ class Apple extends CakeTestModel { */ class Sample extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Sample'; + /** + * name property + * + * @var string + */ + public $name = 'Sample'; + + /** + * belongsTo property + * + * @var string + */ + public $belongsTo = 'Apple'; -/** - * belongsTo property - * - * @var string - */ - public $belongsTo = 'Apple'; } /** @@ -851,19 +864,20 @@ class Sample extends CakeTestModel { */ class AnotherArticle extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'AnotherArticle'; + /** + * name property + * + * @var string + */ + public $name = 'AnotherArticle'; + + /** + * hasMany property + * + * @var string + */ + public $hasMany = 'Home'; -/** - * hasMany property - * - * @var string - */ - public $hasMany = 'Home'; } /** @@ -873,19 +887,20 @@ class AnotherArticle extends CakeTestModel { */ class Advertisement extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Advertisement'; + /** + * name property + * + * @var string + */ + public $name = 'Advertisement'; + + /** + * hasMany property + * + * @var string + */ + public $hasMany = 'Home'; -/** - * hasMany property - * - * @var string - */ - public $hasMany = 'Home'; } /** @@ -895,19 +910,20 @@ class Advertisement extends CakeTestModel { */ class Home extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Home'; + /** + * name property + * + * @var string + */ + public $name = 'Home'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('AnotherArticle', 'Advertisement'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('AnotherArticle', 'Advertisement'); } /** @@ -917,31 +933,31 @@ class Home extends CakeTestModel { */ class Post extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Post'; + /** + * name property + * + * @var string + */ + public $name = 'Post'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Author'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Author'); - public function beforeFind($queryData) { - if (isset($queryData['connection'])) { - $this->useDbConfig = $queryData['connection']; - } - return true; + public function beforeFind($queryData) { + if (isset($queryData['connection'])) { + $this->useDbConfig = $queryData['connection']; } + return true; + } - public function afterFind($results, $primary = false) { - $this->useDbConfig = 'test'; - return $results; - } + public function afterFind($results, $primary = false) { + $this->useDbConfig = 'test'; + return $results; + } } @@ -952,30 +968,30 @@ class Post extends CakeTestModel { */ class Author extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Author'; + /** + * name property + * + * @var string + */ + public $name = 'Author'; -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Post'); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Post'); -/** - * afterFind method - * - * @param array $results - * @return void - */ - public function afterFind($results, $primary = false) { - $results[0]['Author']['test'] = 'working'; - return $results; - } + /** + * afterFind method + * + * @param array $results + * @return void + */ + public function afterFind($results, $primary = false) { + $results[0]['Author']['test'] = 'working'; + return $results; + } } @@ -986,25 +1002,25 @@ class Author extends CakeTestModel { */ class ModifiedAuthor extends Author { -/** - * name property - * - * @var string - */ - public $name = 'Author'; + /** + * name property + * + * @var string + */ + public $name = 'Author'; -/** - * afterFind method - * - * @param array $results - * @return void - */ - public function afterFind($results, $primary = false) { - foreach ($results as $index => $result) { - $results[$index]['Author']['user'] .= ' (CakePHP)'; - } - return $results; + /** + * afterFind method + * + * @param array $results + * @return void + */ + public function afterFind($results, $primary = false) { + foreach ($results as $index => $result) { + $results[$index]['Author']['user'] .= ' (CakePHP)'; } + return $results; + } } @@ -1015,19 +1031,20 @@ class ModifiedAuthor extends Author { */ class Project extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Project'; + /** + * name property + * + * @var string + */ + public $name = 'Project'; + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Thread'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Thread'); } /** @@ -1037,26 +1054,27 @@ class Project extends CakeTestModel { */ class Thread extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Thread'; + /** + * name property + * + * @var string + */ + public $name = 'Thread'; -/** - * hasMany property - * - * @var array - */ - public $belongsTo = array('Project'); + /** + * hasMany property + * + * @var array + */ + public $belongsTo = array('Project'); + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Message'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Message'); } /** @@ -1066,19 +1084,20 @@ class Thread extends CakeTestModel { */ class Message extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Message'; + /** + * name property + * + * @var string + */ + public $name = 'Message'; + + /** + * hasOne property + * + * @var array + */ + public $hasOne = array('Bid'); -/** - * hasOne property - * - * @var array - */ - public $hasOne = array('Bid'); } /** @@ -1088,19 +1107,20 @@ class Message extends CakeTestModel { */ class Bid extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Bid'; + /** + * name property + * + * @var string + */ + public $name = 'Bid'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Message'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Message'); } /** @@ -1110,31 +1130,32 @@ class Bid extends CakeTestModel { */ class BiddingMessage extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'BiddingMessage'; + /** + * name property + * + * @var string + */ + public $name = 'BiddingMessage'; -/** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'bidding'; + /** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'bidding'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Bidding' => array( + 'foreignKey' => false, + 'conditions' => array('BiddingMessage.bidding = Bidding.bid') + ) + ); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Bidding' => array( - 'foreignKey' => false, - 'conditions' => array('BiddingMessage.bidding = Bidding.bid') - ) - ); } /** @@ -1144,25 +1165,26 @@ class BiddingMessage extends CakeTestModel { */ class Bidding extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Bidding'; + /** + * name property + * + * @var string + */ + public $name = 'Bidding'; + + /** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'BiddingMessage' => array( + 'foreignKey' => false, + 'conditions' => array('BiddingMessage.bidding = Bidding.bid'), + 'dependent' => true + ) + ); -/** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'BiddingMessage' => array( - 'foreignKey' => false, - 'conditions' => array('BiddingMessage.bidding = Bidding.bid'), - 'dependent' => true - ) - ); } /** @@ -1172,57 +1194,57 @@ class Bidding extends CakeTestModel { */ class NodeAfterFind extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'NodeAfterFind'; + /** + * name property + * + * @var string + */ + public $name = 'NodeAfterFind'; -/** - * validate property - * - * @var array - */ - public $validate = array('name' => 'notEmpty'); + /** + * validate property + * + * @var array + */ + public $validate = array('name' => 'notEmpty'); -/** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; -/** - * hasOne property - * - * @var array - */ - public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); -/** - * afterFind method - * - * @param mixed $results - * @return array - */ - public function afterFind($results, $primary = false) { - return $results; - } + /** + * afterFind method + * + * @param mixed $results + * @return array + */ + public function afterFind($results, $primary = false) { + return $results; + } } @@ -1233,26 +1255,27 @@ class NodeAfterFind extends CakeTestModel { */ class NodeAfterFindSample extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'NodeAfterFindSample'; + /** + * name property + * + * @var string + */ + public $name = 'NodeAfterFindSample'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'samples'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'samples'; + + /** + * belongsTo property + * + * @var string + */ + public $belongsTo = 'NodeAfterFind'; -/** - * belongsTo property - * - * @var string - */ - public $belongsTo = 'NodeAfterFind'; } /** @@ -1262,47 +1285,48 @@ class NodeAfterFindSample extends CakeTestModel { */ class NodeNoAfterFind extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'NodeAfterFind'; + /** + * name property + * + * @var string + */ + public $name = 'NodeAfterFind'; -/** - * validate property - * - * @var array - */ - public $validate = array('name' => 'notEmpty'); + /** + * validate property + * + * @var array + */ + public $validate = array('name' => 'notEmpty'); -/** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; -/** - * hasOne property - * - * @var array - */ - public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); } /** @@ -1312,27 +1336,28 @@ class NodeNoAfterFind extends CakeTestModel { */ class Node extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Node'; + /** + * name property + * + * @var string + */ + public $name = 'Node'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array( + 'ParentNode' => array( + 'className' => 'Node', + 'joinTable' => 'dependency', + 'with' => 'Dependency', + 'foreignKey' => 'child_id', + 'associationForeignKey' => 'parent_id', + ) + ); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array( - 'ParentNode' => array( - 'className' => 'Node', - 'joinTable' => 'dependency', - 'with' => 'Dependency', - 'foreignKey' => 'child_id', - 'associationForeignKey' => 'parent_id', - ) - ); } /** @@ -1342,12 +1367,13 @@ class Node extends CakeTestModel { */ class Dependency extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Dependency'; + /** + * name property + * + * @var string + */ + public $name = 'Dependency'; + } /** @@ -1357,26 +1383,27 @@ class Dependency extends CakeTestModel { */ class ModelA extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ModelA'; + /** + * name property + * + * @var string + */ + public $name = 'ModelA'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('ModelB', 'ModelC'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('ModelB', 'ModelC'); } /** @@ -1386,26 +1413,27 @@ class ModelA extends CakeTestModel { */ class ModelB extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ModelB'; + /** + * name property + * + * @var string + */ + public $name = 'ModelB'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'messages'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'messages'; + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('ModelD'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('ModelD'); } /** @@ -1415,26 +1443,27 @@ class ModelB extends CakeTestModel { */ class ModelC extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ModelC'; + /** + * name property + * + * @var string + */ + public $name = 'ModelC'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'bids'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'bids'; + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('ModelD'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('ModelD'); } /** @@ -1444,19 +1473,20 @@ class ModelC extends CakeTestModel { */ class ModelD extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ModelD'; + /** + * name property + * + * @var string + */ + public $name = 'ModelD'; + + /** + * useTable property + * + * @var string + */ + public $useTable = 'threads'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'threads'; } /** @@ -1466,19 +1496,20 @@ class ModelD extends CakeTestModel { */ class Something extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Something'; + /** + * name property + * + * @var string + */ + public $name = 'Something'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('SomethingElse' => array('with' => array('JoinThing' => array('doomed')))); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('SomethingElse' => array('with' => array('JoinThing' => array('doomed')))); } /** @@ -1488,19 +1519,20 @@ class Something extends CakeTestModel { */ class SomethingElse extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'SomethingElse'; + /** + * name property + * + * @var string + */ + public $name = 'SomethingElse'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Something' => array('with' => 'JoinThing')); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Something' => array('with' => 'JoinThing')); } /** @@ -1510,19 +1542,20 @@ class SomethingElse extends CakeTestModel { */ class JoinThing extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'JoinThing'; + /** + * name property + * + * @var string + */ + public $name = 'JoinThing'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Something', 'SomethingElse'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Something', 'SomethingElse'); } /** @@ -1532,19 +1565,20 @@ class JoinThing extends CakeTestModel { */ class Portfolio extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Portfolio'; + /** + * name property + * + * @var string + */ + public $name = 'Portfolio'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Item'); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Item'); } /** @@ -1554,26 +1588,27 @@ class Portfolio extends CakeTestModel { */ class Item extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Item'; + /** + * name property + * + * @var string + */ + public $name = 'Item'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Syfile' => array('counterCache' => true)); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Syfile' => array('counterCache' => true)); + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Portfolio' => array('unique' => false)); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Portfolio' => array('unique' => false)); } /** @@ -1583,12 +1618,13 @@ class Item extends CakeTestModel { */ class ItemsPortfolio extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ItemsPortfolio'; + /** + * name property + * + * @var string + */ + public $name = 'ItemsPortfolio'; + } /** @@ -1598,19 +1634,20 @@ class ItemsPortfolio extends CakeTestModel { */ class Syfile extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Syfile'; + /** + * name property + * + * @var string + */ + public $name = 'Syfile'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Image'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Image'); } /** @@ -1620,12 +1657,13 @@ class Syfile extends CakeTestModel { */ class Image extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Image'; + /** + * name property + * + * @var string + */ + public $name = 'Image'; + } /** @@ -1635,37 +1673,38 @@ class Image extends CakeTestModel { */ class DeviceType extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'DeviceType'; + /** + * name property + * + * @var string + */ + public $name = 'DeviceType'; -/** - * order property - * - * @var array - */ - public $order = array('DeviceType.order' => 'ASC'); + /** + * order property + * + * @var array + */ + public $order = array('DeviceType.order' => 'ASC'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', - 'Image' => array('className' => 'Document'), - 'Extra1' => array('className' => 'Document'), - 'Extra2' => array('className' => 'Document')); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', + 'Image' => array('className' => 'Document'), + 'Extra1' => array('className' => 'Document'), + 'Extra2' => array('className' => 'Document')); + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Device' => array('order' => array('Device.id' => 'ASC'))); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Device' => array('order' => array('Device.id' => 'ASC'))); } /** @@ -1675,12 +1714,13 @@ class DeviceType extends CakeTestModel { */ class DeviceTypeCategory extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'DeviceTypeCategory'; + /** + * name property + * + * @var string + */ + public $name = 'DeviceTypeCategory'; + } /** @@ -1690,12 +1730,13 @@ class DeviceTypeCategory extends CakeTestModel { */ class FeatureSet extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'FeatureSet'; + /** + * name property + * + * @var string + */ + public $name = 'FeatureSet'; + } /** @@ -1705,19 +1746,20 @@ class FeatureSet extends CakeTestModel { */ class ExteriorTypeCategory extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ExteriorTypeCategory'; + /** + * name property + * + * @var string + */ + public $name = 'ExteriorTypeCategory'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Image' => array('className' => 'Device')); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Image' => array('className' => 'Device')); } /** @@ -1727,19 +1769,20 @@ class ExteriorTypeCategory extends CakeTestModel { */ class Document extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Document'; + /** + * name property + * + * @var string + */ + public $name = 'Document'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('DocumentDirectory'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('DocumentDirectory'); } /** @@ -1749,12 +1792,13 @@ class Document extends CakeTestModel { */ class Device extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Device'; + /** + * name property + * + * @var string + */ + public $name = 'Device'; + } /** @@ -1764,12 +1808,13 @@ class Device extends CakeTestModel { */ class DocumentDirectory extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'DocumentDirectory'; + /** + * name property + * + * @var string + */ + public $name = 'DocumentDirectory'; + } /** @@ -1779,12 +1824,13 @@ class DocumentDirectory extends CakeTestModel { */ class PrimaryModel extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'PrimaryModel'; + /** + * name property + * + * @var string + */ + public $name = 'PrimaryModel'; + } /** @@ -1794,12 +1840,13 @@ class PrimaryModel extends CakeTestModel { */ class SecondaryModel extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'SecondaryModel'; + /** + * name property + * + * @var string + */ + public $name = 'SecondaryModel'; + } /** @@ -1809,19 +1856,20 @@ class SecondaryModel extends CakeTestModel { */ class JoinA extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'JoinA'; + /** + * name property + * + * @var string + */ + public $name = 'JoinA'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('JoinB', 'JoinC'); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('JoinB', 'JoinC'); } /** @@ -1831,19 +1879,20 @@ class JoinA extends CakeTestModel { */ class JoinB extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'JoinB'; + /** + * name property + * + * @var string + */ + public $name = 'JoinB'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('JoinA'); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('JoinA'); } /** @@ -1853,19 +1902,20 @@ class JoinB extends CakeTestModel { */ class JoinC extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'JoinC'; + /** + * name property + * + * @var string + */ + public $name = 'JoinC'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('JoinA'); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('JoinA'); } /** @@ -1875,33 +1925,34 @@ class JoinC extends CakeTestModel { */ class ThePaper extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ThePaper'; + /** + * name property + * + * @var string + */ + public $name = 'ThePaper'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; -/** - * hasOne property - * - * @var array - */ - public $hasOne = array('Itself' => array('className' => 'ThePaper', 'foreignKey' => 'apple_id')); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array('Itself' => array('className' => 'ThePaper', 'foreignKey' => 'apple_id')); + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Monkey' => array('joinTable' => 'the_paper_monkies', 'order' => 'id')); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Monkey' => array('joinTable' => 'the_paper_monkies', 'order' => 'id')); } /** @@ -1911,19 +1962,20 @@ class ThePaper extends CakeTestModel { */ class Monkey extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Monkey'; + /** + * name property + * + * @var string + */ + public $name = 'Monkey'; + + /** + * useTable property + * + * @var string + */ + public $useTable = 'devices'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'devices'; } /** @@ -1933,28 +1985,29 @@ class Monkey extends CakeTestModel { */ class AssociationTest1 extends CakeTestModel { -/** - * useTable property - * - * @var string - */ - public $useTable = 'join_as'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'join_as'; -/** - * name property - * - * @var string - */ - public $name = 'AssociationTest1'; + /** + * name property + * + * @var string + */ + public $name = 'AssociationTest1'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('AssociationTest2' => array( + 'unique' => false, 'joinTable' => 'join_as_join_bs', 'foreignKey' => false + )); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('AssociationTest2' => array( - 'unique' => false, 'joinTable' => 'join_as_join_bs', 'foreignKey' => false - )); } /** @@ -1964,28 +2017,29 @@ class AssociationTest1 extends CakeTestModel { */ class AssociationTest2 extends CakeTestModel { -/** - * useTable property - * - * @var string - */ - public $useTable = 'join_bs'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'join_bs'; -/** - * name property - * - * @var string - */ - public $name = 'AssociationTest2'; + /** + * name property + * + * @var string + */ + public $name = 'AssociationTest2'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('AssociationTest1' => array( + 'unique' => false, 'joinTable' => 'join_as_join_bs' + )); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('AssociationTest1' => array( - 'unique' => false, 'joinTable' => 'join_as_join_bs' - )); } /** @@ -1994,7 +2048,7 @@ class AssociationTest2 extends CakeTestModel { * @package Cake.Test.Case.Model */ class Callback extends CakeTestModel { - + } /** @@ -2004,55 +2058,55 @@ class Callback extends CakeTestModel { */ class CallbackPostTestModel extends CakeTestModel { - public $useTable = 'posts'; + public $useTable = 'posts'; -/** - * variable to control return of beforeValidate - * - * @var boolean - */ - public $beforeValidateReturn = true; + /** + * variable to control return of beforeValidate + * + * @var boolean + */ + public $beforeValidateReturn = true; -/** - * variable to control return of beforeSave - * - * @var boolean - */ - public $beforeSaveReturn = true; + /** + * variable to control return of beforeSave + * + * @var boolean + */ + public $beforeSaveReturn = true; -/** - * variable to control return of beforeDelete - * - * @var boolean - */ - public $beforeDeleteReturn = true; + /** + * variable to control return of beforeDelete + * + * @var boolean + */ + public $beforeDeleteReturn = true; -/** - * beforeSave callback - * - * @return boolean - */ - public function beforeSave($options = array()) { - return $this->beforeSaveReturn; - } + /** + * beforeSave callback + * + * @return boolean + */ + public function beforeSave($options = array()) { + return $this->beforeSaveReturn; + } -/** - * beforeValidate callback - * - * @return boolean - */ - public function beforeValidate($options = array()) { - return $this->beforeValidateReturn; - } + /** + * beforeValidate callback + * + * @return boolean + */ + public function beforeValidate($options = array()) { + return $this->beforeValidateReturn; + } -/** - * beforeDelete callback - * - * @return boolean - */ - public function beforeDelete($cascade = true) { - return $this->beforeDeleteReturn; - } + /** + * beforeDelete callback + * + * @return boolean + */ + public function beforeDelete($cascade = true) { + return $this->beforeDeleteReturn; + } } @@ -2063,12 +2117,13 @@ class CallbackPostTestModel extends CakeTestModel { */ class Uuid extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Uuid'; + /** + * name property + * + * @var string + */ + public $name = 'Uuid'; + } /** @@ -2078,12 +2133,13 @@ class Uuid extends CakeTestModel { */ class DataTest extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'DataTest'; + /** + * name property + * + * @var string + */ + public $name = 'DataTest'; + } /** @@ -2093,19 +2149,20 @@ class DataTest extends CakeTestModel { */ class TheVoid extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TheVoid'; + /** + * name property + * + * @var string + */ + public $name = 'TheVoid'; + + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; } /** @@ -2115,82 +2172,82 @@ class TheVoid extends CakeTestModel { */ class ValidationTest1 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ValidationTest1'; + /** + * name property + * + * @var string + */ + public $name = 'ValidationTest1'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * schema property - * - * @var array - */ - protected $_schema = array(); + /** + * schema property + * + * @var array + */ + protected $_schema = array(); -/** - * validate property - * - * @var array - */ - public $validate = array( - 'title' => 'notEmpty', - 'published' => 'customValidationMethod', - 'body' => array( - 'notEmpty', - '/^.{5,}$/s' => 'no matchy', - '/^[0-9A-Za-z \\.]{1,}$/s' - ) - ); + /** + * validate property + * + * @var array + */ + public $validate = array( + 'title' => 'notEmpty', + 'published' => 'customValidationMethod', + 'body' => array( + 'notEmpty', + '/^.{5,}$/s' => 'no matchy', + '/^[0-9A-Za-z \\.]{1,}$/s' + ) + ); -/** - * customValidationMethod method - * - * @param mixed $data - * @return void - */ - public function customValidationMethod($data) { - return $data === 1; - } + /** + * customValidationMethod method + * + * @param mixed $data + * @return void + */ + public function customValidationMethod($data) { + return $data === 1; + } -/** - * Custom validator with parameters + default values - * - * @return array - */ - public function customValidatorWithParams($data, $validator, $or = true, $ignoreOnSame = 'id') { - $this->validatorParams = get_defined_vars(); - unset($this->validatorParams['this']); - return true; - } + /** + * Custom validator with parameters + default values + * + * @return array + */ + public function customValidatorWithParams($data, $validator, $or = true, $ignoreOnSame = 'id') { + $this->validatorParams = get_defined_vars(); + unset($this->validatorParams['this']); + return true; + } -/** - * Custom validator with message - * - * @return array - */ - public function customValidatorWithMessage($data) { - return 'This field will *never* validate! Muhahaha!'; - } + /** + * Custom validator with message + * + * @return array + */ + public function customValidatorWithMessage($data) { + return 'This field will *never* validate! Muhahaha!'; + } -/** - * Test validation with many parameters - * - * @return void - */ - public function customValidatorWithSixParams($data, $one = 1, $two = 2, $three = 3, $four = 4, $five = 5, $six = 6) { - $this->validatorParams = get_defined_vars(); - unset($this->validatorParams['this']); - return true; - } + /** + * Test validation with many parameters + * + * @return void + */ + public function customValidatorWithSixParams($data, $one = 1, $two = 2, $three = 3, $four = 4, $five = 5, $six = 6) { + $this->validatorParams = get_defined_vars(); + unset($this->validatorParams['this']); + return true; + } } @@ -2201,53 +2258,53 @@ class ValidationTest1 extends CakeTestModel { */ class ValidationTest2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ValidationTest2'; + /** + * name property + * + * @var string + */ + public $name = 'ValidationTest2'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * validate property - * - * @var array - */ - public $validate = array( - 'title' => 'notEmpty', - 'published' => 'customValidationMethod', - 'body' => array( - 'notEmpty', - '/^.{5,}$/s' => 'no matchy', - '/^[0-9A-Za-z \\.]{1,}$/s' - ) - ); + /** + * validate property + * + * @var array + */ + public $validate = array( + 'title' => 'notEmpty', + 'published' => 'customValidationMethod', + 'body' => array( + 'notEmpty', + '/^.{5,}$/s' => 'no matchy', + '/^[0-9A-Za-z \\.]{1,}$/s' + ) + ); -/** - * customValidationMethod method - * - * @param mixed $data - * @return void - */ - public function customValidationMethod($data) { - return $data === 1; - } + /** + * customValidationMethod method + * + * @param mixed $data + * @return void + */ + public function customValidationMethod($data) { + return $data === 1; + } -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - return array(); - } + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + return array(); + } } @@ -2258,28 +2315,29 @@ class ValidationTest2 extends CakeTestModel { */ class Person extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Person'; + /** + * name property + * + * @var string + */ + public $name = 'Person'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Mother' => array( + 'className' => 'Person', + 'foreignKey' => 'mother_id' + ), + 'Father' => array( + 'className' => 'Person', + 'foreignKey' => 'father_id' + ) + ); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Mother' => array( - 'className' => 'Person', - 'foreignKey' => 'mother_id' - ), - 'Father' => array( - 'className' => 'Person', - 'foreignKey' => 'father_id' - ) - ); } /** @@ -2289,12 +2347,13 @@ class Person extends CakeTestModel { */ class UnderscoreField extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'UnderscoreField'; + /** + * name property + * + * @var string + */ + public $name = 'UnderscoreField'; + } /** @@ -2304,12 +2363,13 @@ class UnderscoreField extends CakeTestModel { */ class Product extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Product'; + /** + * name property + * + * @var string + */ + public $name = 'Product'; + } /** @@ -2319,33 +2379,34 @@ class Product extends CakeTestModel { */ class Story extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Story'; + /** + * name property + * + * @var string + */ + public $name = 'Story'; -/** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'story'; + /** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'story'; -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Tag' => array('foreignKey' => 'story')); + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Tag' => array('foreignKey' => 'story')); + + /** + * validate property + * + * @var array + */ + public $validate = array('title' => 'notEmpty'); -/** - * validate property - * - * @var array - */ - public $validate = array('title' => 'notEmpty'); } /** @@ -2355,25 +2416,25 @@ class Story extends CakeTestModel { */ class Cd extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Cd'; + /** + * name property + * + * @var string + */ + public $name = 'Cd'; -/** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'OverallFavorite' => array( - 'foreignKey' => 'model_id', - 'dependent' => true, - 'conditions' => array('model_type' => 'Cd') - ) - ); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'OverallFavorite' => array( + 'foreignKey' => 'model_id', + 'dependent' => true, + 'conditions' => array('model_type' => 'Cd') + ) + ); } @@ -2384,25 +2445,25 @@ class Cd extends CakeTestModel { */ class Book extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Book'; + /** + * name property + * + * @var string + */ + public $name = 'Book'; -/** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'OverallFavorite' => array( - 'foreignKey' => 'model_id', - 'dependent' => true, - 'conditions' => 'OverallFavorite.model_type = \'Book\'' - ) - ); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'OverallFavorite' => array( + 'foreignKey' => 'model_id', + 'dependent' => true, + 'conditions' => 'OverallFavorite.model_type = \'Book\'' + ) + ); } @@ -2413,12 +2474,13 @@ class Book extends CakeTestModel { */ class OverallFavorite extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'OverallFavorite'; + /** + * name property + * + * @var string + */ + public $name = 'OverallFavorite'; + } /** @@ -2428,19 +2490,20 @@ class OverallFavorite extends CakeTestModel { */ class MyUser extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'MyUser'; + /** + * name property + * + * @var string + */ + public $name = 'MyUser'; + + /** + * undocumented variable + * + * @var string + */ + public $hasAndBelongsToMany = array('MyCategory'); -/** - * undocumented variable - * - * @var string - */ - public $hasAndBelongsToMany = array('MyCategory'); } /** @@ -2450,19 +2513,20 @@ class MyUser extends CakeTestModel { */ class MyCategory extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'MyCategory'; + /** + * name property + * + * @var string + */ + public $name = 'MyCategory'; + + /** + * undocumented variable + * + * @var string + */ + public $hasAndBelongsToMany = array('MyProduct', 'MyUser'); -/** - * undocumented variable - * - * @var string - */ - public $hasAndBelongsToMany = array('MyProduct', 'MyUser'); } /** @@ -2472,19 +2536,20 @@ class MyCategory extends CakeTestModel { */ class MyProduct extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'MyProduct'; + /** + * name property + * + * @var string + */ + public $name = 'MyProduct'; + + /** + * undocumented variable + * + * @var string + */ + public $hasAndBelongsToMany = array('MyCategory'); -/** - * undocumented variable - * - * @var string - */ - public $hasAndBelongsToMany = array('MyCategory'); } /** @@ -2494,12 +2559,13 @@ class MyProduct extends CakeTestModel { */ class MyCategoriesMyUser extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'MyCategoriesMyUser'; + /** + * name property + * + * @var string + */ + public $name = 'MyCategoriesMyUser'; + } /** @@ -2509,14 +2575,14 @@ class MyCategoriesMyUser extends CakeTestModel { */ class MyCategoriesMyProduct extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'MyCategoriesMyProduct'; -} + /** + * name property + * + * @var string + */ + public $name = 'MyCategoriesMyProduct'; +} /** * NumberTree class @@ -2525,61 +2591,61 @@ class MyCategoriesMyProduct extends CakeTestModel { */ class NumberTree extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'NumberTree'; + /** + * name property + * + * @var string + */ + public $name = 'NumberTree'; -/** - * actsAs property - * - * @var array - */ - public $actsAs = array('Tree'); + /** + * actsAs property + * + * @var array + */ + public $actsAs = array('Tree'); -/** - * initialize method - * - * @param integer $levelLimit - * @param integer $childLimit - * @param mixed $currentLevel - * @param mixed $parent_id - * @param string $prefix - * @param boolean $hierarchal - * @return void - */ - public function initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parentId = null, $prefix = '1', $hierarchal = true) { - if (!$parentId) { - $db = ConnectionManager::getDataSource($this->useDbConfig); - $db->truncate($this->table); - $this->save(array($this->name => array('name' => '1. Root'))); - $this->initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierarchal); - $this->create(array()); - } - - if (!$currentLevel || $currentLevel > $levelLimit) { - return; - } - - for ($i = 1; $i <= $childLimit; $i++) { - $name = $prefix . '.' . $i; - $data = array($this->name => array('name' => $name)); - $this->create($data); - - if ($hierarchal) { - if ($this->name === 'UnconventionalTree') { - $data[$this->name]['join'] = $parentId; - } else { - $data[$this->name]['parent_id'] = $parentId; - } - } - $this->save($data); - $this->initialize($levelLimit, $childLimit, $currentLevel + 1, $this->id, $name, $hierarchal); - } + /** + * initialize method + * + * @param integer $levelLimit + * @param integer $childLimit + * @param mixed $currentLevel + * @param mixed $parent_id + * @param string $prefix + * @param boolean $hierarchal + * @return void + */ + public function initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parentId = null, $prefix = '1', $hierarchal = true) { + if (!$parentId) { + $db = ConnectionManager::getDataSource($this->useDbConfig); + $db->truncate($this->table); + $this->save(array($this->name => array('name' => '1. Root'))); + $this->initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierarchal); + $this->create(array()); } + if (!$currentLevel || $currentLevel > $levelLimit) { + return; + } + + for ($i = 1; $i <= $childLimit; $i++) { + $name = $prefix . '.' . $i; + $data = array($this->name => array('name' => $name)); + $this->create($data); + + if ($hierarchal) { + if ($this->name === 'UnconventionalTree') { + $data[$this->name]['join'] = $parentId; + } else { + $data[$this->name]['parent_id'] = $parentId; + } + } + $this->save($data); + $this->initialize($levelLimit, $childLimit, $currentLevel + 1, $this->id, $name, $hierarchal); + } + } + } /** @@ -2589,19 +2655,20 @@ class NumberTree extends CakeTestModel { */ class NumberTreeTwo extends NumberTree { -/** - * name property - * - * @var string - */ - public $name = 'NumberTreeTwo'; + /** + * name property + * + * @var string + */ + public $name = 'NumberTreeTwo'; + + /** + * actsAs property + * + * @var array + */ + public $actsAs = array(); -/** - * actsAs property - * - * @var array - */ - public $actsAs = array(); } /** @@ -2611,12 +2678,13 @@ class NumberTreeTwo extends NumberTree { */ class FlagTree extends NumberTree { -/** - * name property - * - * @var string - */ - public $name = 'FlagTree'; + /** + * name property + * + * @var string + */ + public $name = 'FlagTree'; + } /** @@ -2626,20 +2694,19 @@ class FlagTree extends NumberTree { */ class UnconventionalTree extends NumberTree { -/** - * name property - * - * @var string - */ - public $name = 'UnconventionalTree'; - - public $actsAs = array( - 'Tree' => array( - 'parent' => 'join', - 'left' => 'left', - 'right' => 'right' - ) - ); + /** + * name property + * + * @var string + */ + public $name = 'UnconventionalTree'; + public $actsAs = array( + 'Tree' => array( + 'parent' => 'join', + 'left' => 'left', + 'right' => 'right' + ) + ); } @@ -2650,12 +2717,13 @@ class UnconventionalTree extends NumberTree { */ class UuidTree extends NumberTree { -/** - * name property - * - * @var string - */ - public $name = 'UuidTree'; + /** + * name property + * + * @var string + */ + public $name = 'UuidTree'; + } /** @@ -2665,19 +2733,20 @@ class UuidTree extends NumberTree { */ class Campaign extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Campaign'; + /** + * name property + * + * @var string + */ + public $name = 'Campaign'; + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Ad' => array('fields' => array('id', 'campaign_id', 'name'))); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Ad' => array('fields' => array('id', 'campaign_id', 'name'))); } /** @@ -2687,26 +2756,27 @@ class Campaign extends CakeTestModel { */ class Ad extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Ad'; + /** + * name property + * + * @var string + */ + public $name = 'Ad'; -/** - * actsAs property - * - * @var array - */ - public $actsAs = array('Tree'); + /** + * actsAs property + * + * @var array + */ + public $actsAs = array('Tree'); + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Campaign'); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Campaign'); } /** @@ -2716,25 +2786,25 @@ class Ad extends CakeTestModel { */ class AfterTree extends NumberTree { -/** - * name property - * - * @var string - */ - public $name = 'AfterTree'; + /** + * name property + * + * @var string + */ + public $name = 'AfterTree'; -/** - * actsAs property - * - * @var array - */ - public $actsAs = array('Tree'); + /** + * actsAs property + * + * @var array + */ + public $actsAs = array('Tree'); - public function afterSave($created) { - if ($created && isset($this->data['AfterTree'])) { - $this->data['AfterTree']['name'] = 'Six and One Half Changed in AfterTree::afterSave() but not in database'; - } + public function afterSave($created) { + if ($created && isset($this->data['AfterTree'])) { + $this->data['AfterTree']['name'] = 'Six and One Half Changed in AfterTree::afterSave() but not in database'; } + } } @@ -2745,33 +2815,34 @@ class AfterTree extends NumberTree { */ class Content extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Content'; + /** + * name property + * + * @var string + */ + public $name = 'Content'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'Content'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'Content'; -/** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'iContentId'; + /** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'iContentId'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Account' => array('className' => 'Account', 'with' => 'ContentAccount', 'joinTable' => 'ContentAccounts', 'foreignKey' => 'iContentId', 'associationForeignKey', 'iAccountId')); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Account' => array('className' => 'Account', 'with' => 'ContentAccount', 'joinTable' => 'ContentAccounts', 'foreignKey' => 'iContentId', 'associationForeignKey', 'iAccountId')); } /** @@ -2781,26 +2852,27 @@ class Content extends CakeTestModel { */ class Account extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Account'; + /** + * name property + * + * @var string + */ + public $name = 'Account'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'Accounts'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'Accounts'; + + /** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'iAccountId'; -/** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'iAccountId'; } /** @@ -2810,26 +2882,27 @@ class Account extends CakeTestModel { */ class ContentAccount extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ContentAccount'; + /** + * name property + * + * @var string + */ + public $name = 'ContentAccount'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'ContentAccounts'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'ContentAccounts'; + + /** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'iContentAccountsId'; -/** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'iContentAccountsId'; } /** @@ -2839,7 +2912,7 @@ class ContentAccount extends CakeTestModel { */ class FilmFile extends CakeTestModel { - public $name = 'FilmFile'; + public $name = 'FilmFile'; } @@ -2850,17 +2923,16 @@ class FilmFile extends CakeTestModel { */ class Basket extends CakeTestModel { - public $name = 'Basket'; - - public $belongsTo = array( - 'FilmFile' => array( - 'className' => 'FilmFile', - 'foreignKey' => 'object_id', - 'conditions' => "Basket.type = 'file'", - 'fields' => '', - 'order' => '' - ) - ); + public $name = 'Basket'; + public $belongsTo = array( + 'FilmFile' => array( + 'className' => 'FilmFile', + 'foreignKey' => 'object_id', + 'conditions' => "Basket.type = 'file'", + 'fields' => '', + 'order' => '' + ) + ); } @@ -2871,32 +2943,33 @@ class Basket extends CakeTestModel { */ class TestPluginArticle extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestPluginArticle'; + /** + * name property + * + * @var string + */ + public $name = 'TestPluginArticle'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'TestPluginComment' => array( + 'className' => 'TestPlugin.TestPluginComment', + 'foreignKey' => 'article_id', + 'dependent' => true + ) + ); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'TestPluginComment' => array( - 'className' => 'TestPlugin.TestPluginComment', - 'foreignKey' => 'article_id', - 'dependent' => true - ) - ); } /** @@ -2906,25 +2979,26 @@ class TestPluginArticle extends CakeTestModel { */ class TestPluginComment extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestPluginComment'; + /** + * name property + * + * @var string + */ + public $name = 'TestPluginComment'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestPluginArticle' => array( + 'className' => 'TestPlugin.TestPluginArticle', + 'foreignKey' => 'article_id', + ), + 'TestPlugin.User' + ); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestPluginArticle' => array( - 'className' => 'TestPlugin.TestPluginArticle', - 'foreignKey' => 'article_id', - ), - 'TestPlugin.User' - ); } /** @@ -2934,19 +3008,20 @@ class TestPluginComment extends CakeTestModel { */ class Uuidportfolio extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Uuidportfolio'; + /** + * name property + * + * @var string + */ + public $name = 'Uuidportfolio'; + + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Uuiditem'); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Uuiditem'); } /** @@ -2956,19 +3031,19 @@ class Uuidportfolio extends CakeTestModel { */ class Uuiditem extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Uuiditem'; + /** + * name property + * + * @var string + */ + public $name = 'Uuiditem'; -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolioNumericid')); + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolioNumericid')); } @@ -2979,12 +3054,13 @@ class Uuiditem extends CakeTestModel { */ class UuiditemsUuidportfolio extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'UuiditemsUuidportfolio'; + /** + * name property + * + * @var string + */ + public $name = 'UuiditemsUuidportfolio'; + } /** @@ -2994,12 +3070,13 @@ class UuiditemsUuidportfolio extends CakeTestModel { */ class UuiditemsUuidportfolioNumericid extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'UuiditemsUuidportfolioNumericid'; + /** + * name property + * + * @var string + */ + public $name = 'UuiditemsUuidportfolioNumericid'; + } /** @@ -3009,26 +3086,27 @@ class UuiditemsUuidportfolioNumericid extends CakeTestModel { */ class TranslateTestModel extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TranslateTestModel'; + /** + * name property + * + * @var string + */ + public $name = 'TranslateTestModel'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'i18n'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'i18n'; + + /** + * displayField property + * + * @var string + */ + public $displayField = 'field'; -/** - * displayField property - * - * @var string - */ - public $displayField = 'field'; } /** @@ -3038,26 +3116,26 @@ class TranslateTestModel extends CakeTestModel { */ class TranslateWithPrefix extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TranslateWithPrefix'; + /** + * name property + * + * @var string + */ + public $name = 'TranslateWithPrefix'; -/** - * tablePrefix property - * - * @var string - */ - public $tablePrefix = 'i18n_'; + /** + * tablePrefix property + * + * @var string + */ + public $tablePrefix = 'i18n_'; -/** - * displayField property - * - * @var string - */ - public $displayField = 'field'; + /** + * displayField property + * + * @var string + */ + public $displayField = 'field'; } @@ -3068,33 +3146,33 @@ class TranslateWithPrefix extends CakeTestModel { */ class TranslatedItem extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TranslatedItem'; + /** + * name property + * + * @var string + */ + public $name = 'TranslatedItem'; -/** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; + /** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; -/** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('content', 'title')); + /** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('content', 'title')); -/** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateTestModel'; + /** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateTestModel'; } @@ -3105,33 +3183,33 @@ class TranslatedItem extends CakeTestModel { */ class TranslatedItem2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TranslatedItem'; + /** + * name property + * + * @var string + */ + public $name = 'TranslatedItem'; -/** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; + /** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; -/** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('content', 'title')); + /** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('content', 'title')); -/** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateWithPrefix'; + /** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateWithPrefix'; } @@ -3142,47 +3220,47 @@ class TranslatedItem2 extends CakeTestModel { */ class TranslatedItemWithTable extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TranslatedItemWithTable'; + /** + * name property + * + * @var string + */ + public $name = 'TranslatedItemWithTable'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'translated_items'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'translated_items'; -/** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; + /** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; -/** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('content', 'title')); + /** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('content', 'title')); -/** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateTestModel'; + /** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateTestModel'; -/** - * translateTable property - * - * @var string - */ - public $translateTable = 'another_i18n'; + /** + * translateTable property + * + * @var string + */ + public $translateTable = 'another_i18n'; } @@ -3193,26 +3271,26 @@ class TranslatedItemWithTable extends CakeTestModel { */ class TranslateArticleModel extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TranslateArticleModel'; + /** + * name property + * + * @var string + */ + public $name = 'TranslateArticleModel'; -/** - * useTable property - * - * @var string - */ - public $useTable = 'article_i18n'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'article_i18n'; -/** - * displayField property - * - * @var string - */ - public $displayField = 'field'; + /** + * displayField property + * + * @var string + */ + public $displayField = 'field'; } @@ -3223,299 +3301,273 @@ class TranslateArticleModel extends CakeTestModel { */ class TranslatedArticle extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TranslatedArticle'; + /** + * name property + * + * @var string + */ + public $name = 'TranslatedArticle'; -/** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; + /** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; -/** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('title', 'body')); + /** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('title', 'body')); -/** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateArticleModel'; + /** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateArticleModel'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); -/** - * belongsTo property - * - * @var array - */ - public $hasMany = array('TranslatedItem'); + /** + * belongsTo property + * + * @var array + */ + public $hasMany = array('TranslatedItem'); } class CounterCacheUser extends CakeTestModel { - public $name = 'CounterCacheUser'; + public $name = 'CounterCacheUser'; + public $alias = 'User'; + public $hasMany = array( + 'Post' => array( + 'className' => 'CounterCachePost', + 'foreignKey' => 'user_id' + ) + ); - public $alias = 'User'; - - public $hasMany = array( - 'Post' => array( - 'className' => 'CounterCachePost', - 'foreignKey' => 'user_id' - ) - ); } class CounterCachePost extends CakeTestModel { - public $name = 'CounterCachePost'; + public $name = 'CounterCachePost'; + public $alias = 'Post'; + public $belongsTo = array( + 'User' => array( + 'className' => 'CounterCacheUser', + 'foreignKey' => 'user_id', + 'counterCache' => true + ) + ); - public $alias = 'Post'; - - public $belongsTo = array( - 'User' => array( - 'className' => 'CounterCacheUser', - 'foreignKey' => 'user_id', - 'counterCache' => true - ) - ); } class CounterCacheUserNonstandardPrimaryKey extends CakeTestModel { - public $name = 'CounterCacheUserNonstandardPrimaryKey'; - - public $alias = 'User'; - - public $primaryKey = 'uid'; - - public $hasMany = array( - 'Post' => array( - 'className' => 'CounterCachePostNonstandardPrimaryKey', - 'foreignKey' => 'uid' - ) - ); + public $name = 'CounterCacheUserNonstandardPrimaryKey'; + public $alias = 'User'; + public $primaryKey = 'uid'; + public $hasMany = array( + 'Post' => array( + 'className' => 'CounterCachePostNonstandardPrimaryKey', + 'foreignKey' => 'uid' + ) + ); } class CounterCachePostNonstandardPrimaryKey extends CakeTestModel { - public $name = 'CounterCachePostNonstandardPrimaryKey'; - - public $alias = 'Post'; - - public $primaryKey = 'pid'; - - public $belongsTo = array( - 'User' => array( - 'className' => 'CounterCacheUserNonstandardPrimaryKey', - 'foreignKey' => 'uid', - 'counterCache' => true - ) - ); + public $name = 'CounterCachePostNonstandardPrimaryKey'; + public $alias = 'Post'; + public $primaryKey = 'pid'; + public $belongsTo = array( + 'User' => array( + 'className' => 'CounterCacheUserNonstandardPrimaryKey', + 'foreignKey' => 'uid', + 'counterCache' => true + ) + ); } class ArticleB extends CakeTestModel { - public $name = 'ArticleB'; - - public $useTable = 'articles'; - - public $hasAndBelongsToMany = array( - 'TagB' => array( - 'className' => 'TagB', - 'joinTable' => 'articles_tags', - 'foreignKey' => 'article_id', - 'associationForeignKey' => 'tag_id' - ) - ); + public $name = 'ArticleB'; + public $useTable = 'articles'; + public $hasAndBelongsToMany = array( + 'TagB' => array( + 'className' => 'TagB', + 'joinTable' => 'articles_tags', + 'foreignKey' => 'article_id', + 'associationForeignKey' => 'tag_id' + ) + ); } class TagB extends CakeTestModel { - public $name = 'TagB'; - - public $useTable = 'tags'; - - public $hasAndBelongsToMany = array( - 'ArticleB' => array( - 'className' => 'ArticleB', - 'joinTable' => 'articles_tags', - 'foreignKey' => 'tag_id', - 'associationForeignKey' => 'article_id' - ) - ); + public $name = 'TagB'; + public $useTable = 'tags'; + public $hasAndBelongsToMany = array( + 'ArticleB' => array( + 'className' => 'ArticleB', + 'joinTable' => 'articles_tags', + 'foreignKey' => 'tag_id', + 'associationForeignKey' => 'article_id' + ) + ); } class Fruit extends CakeTestModel { - public $name = 'Fruit'; - - public $hasAndBelongsToMany = array( - 'UuidTag' => array( - 'className' => 'UuidTag', - 'joinTable' => 'fruits_uuid_tags', - 'foreignKey' => 'fruit_id', - 'associationForeignKey' => 'uuid_tag_id', - 'with' => 'FruitsUuidTag' - ) - ); + public $name = 'Fruit'; + public $hasAndBelongsToMany = array( + 'UuidTag' => array( + 'className' => 'UuidTag', + 'joinTable' => 'fruits_uuid_tags', + 'foreignKey' => 'fruit_id', + 'associationForeignKey' => 'uuid_tag_id', + 'with' => 'FruitsUuidTag' + ) + ); } class FruitsUuidTag extends CakeTestModel { - public $name = 'FruitsUuidTag'; - - public $primaryKey = false; - - public $belongsTo = array( - 'UuidTag' => array( - 'className' => 'UuidTag', - 'foreignKey' => 'uuid_tag_id', - ), - 'Fruit' => array( - 'className' => 'Fruit', - 'foreignKey' => 'fruit_id', - ) - ); + public $name = 'FruitsUuidTag'; + public $primaryKey = false; + public $belongsTo = array( + 'UuidTag' => array( + 'className' => 'UuidTag', + 'foreignKey' => 'uuid_tag_id', + ), + 'Fruit' => array( + 'className' => 'Fruit', + 'foreignKey' => 'fruit_id', + ) + ); } class UuidTag extends CakeTestModel { - public $name = 'UuidTag'; - - public $hasAndBelongsToMany = array( - 'Fruit' => array( - 'className' => 'Fruit', - 'joinTable' => 'fruits_uuid_tags', - 'foreign_key' => 'uuid_tag_id', - 'associationForeignKey' => 'fruit_id', - 'with' => 'FruitsUuidTag' - ) - ); + public $name = 'UuidTag'; + public $hasAndBelongsToMany = array( + 'Fruit' => array( + 'className' => 'Fruit', + 'joinTable' => 'fruits_uuid_tags', + 'foreign_key' => 'uuid_tag_id', + 'associationForeignKey' => 'fruit_id', + 'with' => 'FruitsUuidTag' + ) + ); } class FruitNoWith extends CakeTestModel { - public $name = 'Fruit'; - - public $useTable = 'fruits'; - - public $hasAndBelongsToMany = array( - 'UuidTag' => array( - 'className' => 'UuidTagNoWith', - 'joinTable' => 'fruits_uuid_tags', - 'foreignKey' => 'fruit_id', - 'associationForeignKey' => 'uuid_tag_id', - ) - ); + public $name = 'Fruit'; + public $useTable = 'fruits'; + public $hasAndBelongsToMany = array( + 'UuidTag' => array( + 'className' => 'UuidTagNoWith', + 'joinTable' => 'fruits_uuid_tags', + 'foreignKey' => 'fruit_id', + 'associationForeignKey' => 'uuid_tag_id', + ) + ); } class UuidTagNoWith extends CakeTestModel { - public $name = 'UuidTag'; - - public $useTable = 'uuid_tags'; - - public $hasAndBelongsToMany = array( - 'Fruit' => array( - 'className' => 'FruitNoWith', - 'joinTable' => 'fruits_uuid_tags', - 'foreign_key' => 'uuid_tag_id', - 'associationForeignKey' => 'fruit_id', - ) - ); + public $name = 'UuidTag'; + public $useTable = 'uuid_tags'; + public $hasAndBelongsToMany = array( + 'Fruit' => array( + 'className' => 'FruitNoWith', + 'joinTable' => 'fruits_uuid_tags', + 'foreign_key' => 'uuid_tag_id', + 'associationForeignKey' => 'fruit_id', + ) + ); } class ProductUpdateAll extends CakeTestModel { - public $name = 'ProductUpdateAll'; - - public $useTable = 'product_update_all'; + public $name = 'ProductUpdateAll'; + public $useTable = 'product_update_all'; } class GroupUpdateAll extends CakeTestModel { - public $name = 'GroupUpdateAll'; - - public $useTable = 'group_update_all'; + public $name = 'GroupUpdateAll'; + public $useTable = 'group_update_all'; } class TransactionTestModel extends CakeTestModel { - public $name = 'TransactionTestModel'; + public $name = 'TransactionTestModel'; + public $useTable = 'samples'; - public $useTable = 'samples'; - - public function afterSave($created) { - $data = array( - array('apple_id' => 1, 'name' => 'sample6'), - ); - $this->saveAll($data, array('atomic' => true, 'callbacks' => false)); - } + public function afterSave($created) { + $data = array( + array('apple_id' => 1, 'name' => 'sample6'), + ); + $this->saveAll($data, array('atomic' => true, 'callbacks' => false)); + } } class TransactionManyTestModel extends CakeTestModel { - public $name = 'TransactionManyTestModel'; + public $name = 'TransactionManyTestModel'; + public $useTable = 'samples'; - public $useTable = 'samples'; - - public function afterSave($created) { - $data = array( - array('apple_id' => 1, 'name' => 'sample6'), - ); - $this->saveMany($data, array('atomic' => true, 'callbacks' => false)); - } + public function afterSave($created) { + $data = array( + array('apple_id' => 1, 'name' => 'sample6'), + ); + $this->saveMany($data, array('atomic' => true, 'callbacks' => false)); + } } class Site extends CakeTestModel { - public $name = 'Site'; + public $name = 'Site'; + public $useTable = 'sites'; + public $hasAndBelongsToMany = array( + 'Domain' => array('unique' => 'keepExisting'), + ); - public $useTable = 'sites'; - - public $hasAndBelongsToMany = array( - 'Domain' => array('unique' => 'keepExisting'), - ); } class Domain extends CakeTestModel { - public $name = 'Domain'; + public $name = 'Domain'; + public $useTable = 'domains'; + public $hasAndBelongsToMany = array( + 'Site' => array('unique' => 'keepExisting'), + ); - public $useTable = 'domains'; - - public $hasAndBelongsToMany = array( - 'Site' => array('unique' => 'keepExisting'), - ); } /** @@ -3525,71 +3577,71 @@ class Domain extends CakeTestModel { */ class TestModel extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), - 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => '155'), - 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); + /** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), + 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => '155'), + 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); -/** - * find method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function find($conditions = null, $fields = null, $order = null, $recursive = null) { - return array($conditions, $fields); - } + /** + * find method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function find($conditions = null, $fields = null, $order = null, $recursive = null) { + return array($conditions, $fields); + } -/** - * findAll method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } + /** + * findAll method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } } @@ -3600,19 +3652,20 @@ class TestModel extends CakeTestModel { */ class TestModel2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel2'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel2'; + + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; } /** @@ -3622,19 +3675,20 @@ class TestModel2 extends CakeTestModel { */ class TestModel3 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel3'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel3'; + + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; } /** @@ -3644,80 +3698,80 @@ class TestModel3 extends CakeTestModel { */ class TestModel4 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel4'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel4'; -/** - * table property - * - * @var string - */ - public $table = 'test_model4'; + /** + * table property + * + * @var string + */ + public $table = 'test_model4'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestModel4Parent' => array( - 'className' => 'TestModel4', - 'foreignKey' => 'parent_id' - ) - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestModel4Parent' => array( + 'className' => 'TestModel4', + 'foreignKey' => 'parent_id' + ) + ); -/** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'TestModel5' => array( - 'className' => 'TestModel5', - 'foreignKey' => 'test_model4_id' - ) - ); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'TestModel5' => array( + 'className' => 'TestModel5', + 'foreignKey' => 'test_model4_id' + ) + ); -/** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('TestModel7' => array( - 'className' => 'TestModel7', - 'joinTable' => 'test_model4_test_model7', - 'foreignKey' => 'test_model4_id', - 'associationForeignKey' => 'test_model7_id', - 'with' => 'TestModel4TestModel7' - )); + /** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('TestModel7' => array( + 'className' => 'TestModel7', + 'joinTable' => 'test_model4_test_model7', + 'foreignKey' => 'test_model4_id', + 'associationForeignKey' => 'test_model7_id', + 'with' => 'TestModel4TestModel7' + )); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } + return $this->_schema; + } } @@ -3728,41 +3782,41 @@ class TestModel4 extends CakeTestModel { */ class TestModel4TestModel7 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel4TestModel7'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel4TestModel7'; -/** - * table property - * - * @var string - */ - public $table = 'test_model4_test_model7'; + /** + * table property + * + * @var string + */ + public $table = 'test_model4_test_model7'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8') - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8') + ); } + return $this->_schema; + } } @@ -3773,64 +3827,64 @@ class TestModel4TestModel7 extends CakeTestModel { */ class TestModel5 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel5'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel5'; -/** - * table property - * - * @var string - */ - public $table = 'test_model5'; + /** + * table property + * + * @var string + */ + public $table = 'test_model5'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('TestModel4' => array( - 'className' => 'TestModel4', - 'foreignKey' => 'test_model4_id' - )); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('TestModel4' => array( + 'className' => 'TestModel4', + 'foreignKey' => 'test_model4_id' + )); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('TestModel6' => array( - 'className' => 'TestModel6', - 'foreignKey' => 'test_model5_id' - )); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('TestModel6' => array( + 'className' => 'TestModel6', + 'foreignKey' => 'test_model5_id' + )); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } + return $this->_schema; + } } @@ -3841,56 +3895,56 @@ class TestModel5 extends CakeTestModel { */ class TestModel6 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel6'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel6'; -/** - * table property - * - * @var string - */ - public $table = 'test_model6'; + /** + * table property + * + * @var string + */ + public $table = 'test_model6'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestModel5' => array( - 'className' => 'TestModel5', - 'foreignKey' => 'test_model5_id' - ) - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestModel5' => array( + 'className' => 'TestModel5', + 'foreignKey' => 'test_model5_id' + ) + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model5_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model5_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } + return $this->_schema; + } } @@ -3901,43 +3955,43 @@ class TestModel6 extends CakeTestModel { */ class TestModel7 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel7'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel7'; -/** - * table property - * - * @var string - */ - public $table = 'test_model7'; + /** + * table property + * + * @var string + */ + public $table = 'test_model7'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } + return $this->_schema; + } } @@ -3948,57 +4002,57 @@ class TestModel7 extends CakeTestModel { */ class TestModel8 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel8'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel8'; -/** - * table property - * - * @var string - */ - public $table = 'test_model8'; + /** + * table property + * + * @var string + */ + public $table = 'test_model8'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'TestModel9' => array( - 'className' => 'TestModel9', - 'foreignKey' => 'test_model8_id', - 'conditions' => 'TestModel9.name != \'mariano\'' - ) - ); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'TestModel9' => array( + 'className' => 'TestModel9', + 'foreignKey' => 'test_model8_id', + 'conditions' => 'TestModel9.name != \'mariano\'' + ) + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model9_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model9_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } + return $this->_schema; + } } @@ -4009,57 +4063,57 @@ class TestModel8 extends CakeTestModel { */ class TestModel9 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'TestModel9'; + /** + * name property + * + * @var string + */ + public $name = 'TestModel9'; -/** - * table property - * - * @var string - */ - public $table = 'test_model9'; + /** + * table property + * + * @var string + */ + public $table = 'test_model9'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestModel8' => array( - 'className' => 'TestModel8', - 'foreignKey' => 'test_model8_id', - 'conditions' => 'TestModel8.name != \'larry\'' - ) - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestModel8' => array( + 'className' => 'TestModel8', + 'foreignKey' => 'test_model8_id', + 'conditions' => 'TestModel8.name != \'larry\'' + ) + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model8_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model8_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } + return $this->_schema; + } } @@ -4070,55 +4124,55 @@ class TestModel9 extends CakeTestModel { */ class Level extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Level'; + /** + * name property + * + * @var string + */ + public $name = 'Level'; -/** - * table property - * - * @var string - */ - public $table = 'level'; + /** + * table property + * + * @var string + */ + public $table = 'level'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Group' => array( - 'className' => 'Group' - ), - 'User2' => array( - 'className' => 'User2' - ) - ); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Group' => array( + 'className' => 'Group' + ), + 'User2' => array( + 'className' => 'User2' + ) + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); } + return $this->_schema; + } } @@ -4129,56 +4183,56 @@ class Level extends CakeTestModel { */ class Group extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Group'; + /** + * name property + * + * @var string + */ + public $name = 'Group'; -/** - * table property - * - * @var string - */ - public $table = 'group'; + /** + * table property + * + * @var string + */ + public $table = 'group'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Level'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Level'); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array('Category2', 'User2'); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array('Category2', 'User2'); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); } + return $this->_schema; + } } @@ -4189,68 +4243,68 @@ class Group extends CakeTestModel { */ class User2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'User2'; + /** + * name property + * + * @var string + */ + public $name = 'User2'; -/** - * table property - * - * @var string - */ - public $table = 'user'; + /** + * table property + * + * @var string + */ + public $table = 'user'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Group' => array( - 'className' => 'Group' - ), - 'Level' => array( - 'className' => 'Level' - ) - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Group' => array( + 'className' => 'Group' + ), + 'Level' => array( + 'className' => 'Level' + ) + ); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Article2' => array( - 'className' => 'Article2' - ), - ); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Article2' => array( + 'className' => 'Article2' + ), + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); } + return $this->_schema; + } } @@ -4261,79 +4315,78 @@ class User2 extends CakeTestModel { */ class Category2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Category2'; + /** + * name property + * + * @var string + */ + public $name = 'Category2'; -/** - * table property - * - * @var string - */ - public $table = 'category'; + /** + * table property + * + * @var string + */ + public $table = 'category'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Group' => array( - 'className' => 'Group', - 'foreignKey' => 'group_id' - ), - 'ParentCat' => array( - 'className' => 'Category2', - 'foreignKey' => 'parent_id' - ) - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Group' => array( + 'className' => 'Group', + 'foreignKey' => 'group_id' + ), + 'ParentCat' => array( + 'className' => 'Category2', + 'foreignKey' => 'parent_id' + ) + ); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'ChildCat' => array( - 'className' => 'Category2', - 'foreignKey' => 'parent_id' - ), - 'Article2' => array( - 'className' => 'Article2', - 'order' => 'Article2.published_date DESC', - 'foreignKey' => 'category_id', - 'limit' => '3') - ); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'ChildCat' => array( + 'className' => 'Category2', + 'foreignKey' => 'parent_id' + ), + 'Article2' => array( + 'className' => 'Article2', + 'order' => 'Article2.published_date DESC', + 'foreignKey' => 'category_id', + 'limit' => '3') + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'group_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null), - - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'group_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null), + ); } + return $this->_schema; + } } @@ -4344,68 +4397,68 @@ class Category2 extends CakeTestModel { */ class Article2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Article2'; + /** + * name property + * + * @var string + */ + public $name = 'Article2'; -/** - * table property - * - * @var string - */ - public $table = 'articles'; + /** + * table property + * + * @var string + */ + public $table = 'articles'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Category2' => array('className' => 'Category2'), - 'User2' => array('className' => 'User2') - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Category2' => array('className' => 'Category2'), + 'User2' => array('className' => 'User2') + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'rate_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'rate_sum' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'viewed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'version' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => '45'), - 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '200'), - 'intro' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'comments' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '4'), - 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'isdraft' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'allow_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), - 'moderate_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), - 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'multipage' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), - 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), - 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'rate_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'rate_sum' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'viewed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'version' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => '45'), + 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '200'), + 'intro' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'comments' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '4'), + 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'isdraft' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'allow_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), + 'moderate_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), + 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'multipage' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) + ); } + return $this->_schema; + } } @@ -4416,44 +4469,44 @@ class Article2 extends CakeTestModel { */ class CategoryFeatured2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'CategoryFeatured2'; + /** + * name property + * + * @var string + */ + public $name = 'CategoryFeatured2'; -/** - * table property - * - * @var string - */ - public $table = 'category_featured'; + /** + * table property + * + * @var string + */ + public $table = 'category_featured'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'description' => array('text' => 'string', 'null' => false, 'default' => '', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'description' => array('text' => 'string', 'null' => false, 'default' => '', 'length' => null) + ); } + return $this->_schema; + } } @@ -4464,54 +4517,54 @@ class CategoryFeatured2 extends CakeTestModel { */ class Featured2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Featured2'; + /** + * name property + * + * @var string + */ + public $name = 'Featured2'; -/** - * table property - * - * @var string - */ - public $table = 'featured2'; + /** + * table property + * + * @var string + */ + public $table = 'featured2'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'CategoryFeatured2' => array( - 'className' => 'CategoryFeatured2' - ) - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'CategoryFeatured2' => array( + 'className' => 'CategoryFeatured2' + ) + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'article_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'article_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') + ); } + return $this->_schema; + } } @@ -4522,50 +4575,50 @@ class Featured2 extends CakeTestModel { */ class Comment2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'Comment2'; + /** + * name property + * + * @var string + */ + public $name = 'Comment2'; -/** - * table property - * - * @var string - */ - public $table = 'comment'; + /** + * table property + * + * @var string + */ + public $table = 'comment'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('ArticleFeatured2', 'User2'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('ArticleFeatured2', 'User2'); -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'article_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'article_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') + ); } + return $this->_schema; + } } @@ -4576,76 +4629,76 @@ class Comment2 extends CakeTestModel { */ class ArticleFeatured2 extends CakeTestModel { -/** - * name property - * - * @var string - */ - public $name = 'ArticleFeatured2'; + /** + * name property + * + * @var string + */ + public $name = 'ArticleFeatured2'; -/** - * table property - * - * @var string - */ - public $table = 'article_featured'; + /** + * table property + * + * @var string + */ + public $table = 'article_featured'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'CategoryFeatured2' => array('className' => 'CategoryFeatured2'), - 'User2' => array('className' => 'User2') - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'CategoryFeatured2' => array('className' => 'CategoryFeatured2'), + 'User2' => array('className' => 'User2') + ); -/** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'Featured2' => array('className' => 'Featured2') - ); + /** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'Featured2' => array('className' => 'Featured2') + ); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Comment2' => array('className' => 'Comment2', 'dependent' => true) - ); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Comment2' => array('className' => 'Comment2', 'dependent' => true) + ); -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'category_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), - 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), - 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) - ); - } - return $this->_schema; + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'category_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) + ); } + return $this->_schema; + } } @@ -4656,73 +4709,73 @@ class ArticleFeatured2 extends CakeTestModel { */ class MysqlTestModel extends Model { -/** - * name property - * - * @var string - */ - public $name = 'MysqlTestModel'; + /** + * name property + * + * @var string + */ + public $name = 'MysqlTestModel'; -/** - * useTable property - * - * @var bool false - */ - public $useTable = false; + /** + * useTable property + * + * @var bool false + */ + public $useTable = false; -/** - * find method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function find($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } + /** + * find method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function find($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } -/** - * findAll method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } + /** + * findAll method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } -/** - * schema method - * - * @return void - */ - public function schema($field = false) { - return array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), - 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''), - 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } + /** + * schema method + * + * @return void + */ + public function schema($field = false) { + return array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), + 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''), + 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } } @@ -4731,13 +4784,13 @@ class MysqlTestModel extends Model { * */ class PrefixTestModel extends CakeTestModel { + } class PrefixTestUseTableModel extends CakeTestModel { - public $name = 'PrefixTest'; - - public $useTable = 'prefix_tests'; + public $name = 'PrefixTest'; + public $useTable = 'prefix_tests'; } @@ -4748,50 +4801,50 @@ class PrefixTestUseTableModel extends CakeTestModel { */ class ScaffoldMock extends CakeTestModel { -/** - * useTable property - * - * @var string - */ - public $useTable = 'articles'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'articles'; -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'User' => array( - 'className' => 'ScaffoldUser', - 'foreignKey' => 'user_id', - ) - ); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'User' => array( + 'className' => 'ScaffoldUser', + 'foreignKey' => 'user_id', + ) + ); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Comment' => array( - 'className' => 'ScaffoldComment', - 'foreignKey' => 'article_id', - ) - ); + /** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Comment' => array( + 'className' => 'ScaffoldComment', + 'foreignKey' => 'article_id', + ) + ); -/** - * hasAndBelongsToMany property - * - * @var string - */ - public $hasAndBelongsToMany = array( - 'ScaffoldTag' => array( - 'className' => 'ScaffoldTag', - 'foreignKey' => 'something_id', - 'associationForeignKey' => 'something_else_id', - 'joinTable' => 'join_things' - ) - ); + /** + * hasAndBelongsToMany property + * + * @var string + */ + public $hasAndBelongsToMany = array( + 'ScaffoldTag' => array( + 'className' => 'ScaffoldTag', + 'foreignKey' => 'something_id', + 'associationForeignKey' => 'something_else_id', + 'joinTable' => 'join_things' + ) + ); } @@ -4802,24 +4855,25 @@ class ScaffoldMock extends CakeTestModel { */ class ScaffoldUser extends CakeTestModel { -/** - * useTable property - * - * @var string - */ - public $useTable = 'users'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'users'; + + /** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Article' => array( + 'className' => 'ScaffoldMock', + 'foreignKey' => 'article_id', + ) + ); -/** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Article' => array( - 'className' => 'ScaffoldMock', - 'foreignKey' => 'article_id', - ) - ); } /** @@ -4829,24 +4883,25 @@ class ScaffoldUser extends CakeTestModel { */ class ScaffoldComment extends CakeTestModel { -/** - * useTable property - * - * @var string - */ - public $useTable = 'comments'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'comments'; + + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Article' => array( + 'className' => 'ScaffoldMock', + 'foreignKey' => 'article_id', + ) + ); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Article' => array( - 'className' => 'ScaffoldMock', - 'foreignKey' => 'article_id', - ) - ); } /** @@ -4856,12 +4911,12 @@ class ScaffoldComment extends CakeTestModel { */ class ScaffoldTag extends CakeTestModel { -/** - * useTable property - * - * @var string - */ - public $useTable = 'tags'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'tags'; } @@ -4872,12 +4927,12 @@ class ScaffoldTag extends CakeTestModel { */ class Player extends CakeTestModel { - public $hasAndBelongsToMany = array( - 'Guild' => array( - 'with' => 'GuildsPlayer', - 'unique' => true, - ), - ); + public $hasAndBelongsToMany = array( + 'Guild' => array( + 'with' => 'GuildsPlayer', + 'unique' => true, + ), + ); } @@ -4888,12 +4943,12 @@ class Player extends CakeTestModel { */ class Guild extends CakeTestModel { - public $hasAndBelongsToMany = array( - 'Player' => array( - 'with' => 'GuildsPlayer', - 'unique' => true, - ), - ); + public $hasAndBelongsToMany = array( + 'Player' => array( + 'with' => 'GuildsPlayer', + 'unique' => true, + ), + ); } @@ -4904,12 +4959,12 @@ class Guild extends CakeTestModel { */ class GuildsPlayer extends CakeTestModel { - public $useDbConfig = 'test2'; + public $useDbConfig = 'test2'; + public $belongsTo = array( + 'Player', + 'Guild', + ); - public $belongsTo = array( - 'Player', - 'Guild', - ); } /** @@ -4919,11 +4974,11 @@ class GuildsPlayer extends CakeTestModel { */ class Armor extends CakeTestModel { - public $useDbConfig = 'test2'; + public $useDbConfig = 'test2'; + public $hasAndBelongsToMany = array( + 'Player' => array('with' => 'ArmorsPlayer'), + ); - public $hasAndBelongsToMany = array( - 'Player' => array('with' => 'ArmorsPlayer'), - ); } /** @@ -4933,7 +4988,7 @@ class Armor extends CakeTestModel { */ class ArmorsPlayer extends CakeTestModel { - public $useDbConfig = 'test_database_three'; + public $useDbConfig = 'test_database_three'; } @@ -4944,52 +4999,84 @@ class ArmorsPlayer extends CakeTestModel { */ class CustomArticle extends AppModel { -/** - * useTable property - * - * @var string - */ - public $useTable = 'articles'; + /** + * useTable property + * + * @var string + */ + public $useTable = 'articles'; -/** - * findMethods property - * - * @var array - */ - public $findMethods = array('unPublished' => true); + /** + * findMethods property + * + * @var array + */ + public $findMethods = array('unPublished' => true); -/** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); + /** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); -/** - * _findUnPublished custom find - * - * @return array - */ - protected function _findUnPublished($state, $query, $results = array()) { - if ($state === 'before') { - $query['conditions']['published'] = 'N'; - return $query; - } - return $results; + /** + * _findUnPublished custom find + * + * @return array + */ + protected function _findUnPublished($state, $query, $results = array()) { + if ($state === 'before') { + $query['conditions']['published'] = 'N'; + return $query; } + return $results; + } -/** - * Alters title data - * - * @return void - */ - public function beforeValidate($options = array()) { - $this->data[$this->alias]['title'] = 'foo'; - if ($this->findMethods['unPublished'] === true) { - $this->findMethods['unPublished'] = false; - } else { - $this->findMethods['unPublished'] = 'true again'; - } + /** + * Alters title data + * + * @return void + */ + public function beforeValidate($options = array()) { + $this->data[$this->alias]['title'] = 'foo'; + if ($this->findMethods['unPublished'] === true) { + $this->findMethods['unPublished'] = false; + } else { + $this->findMethods['unPublished'] = 'true again'; } + } + +} + +/** + * ModelWithRelations class + * + * @package Cake.Test.Case.Model + */ +class ModelWithRelations extends CakeTestModel { + +} + +/** + * ModelRelated class + * + * @package Cake.Test.Case.Model + */ +class ModelRelated extends CakeTestModel { + + /** + * afterFind callback method + * + * @param array $results + * @param boolean $primary + * @return array Modified $results + */ + public function afterFind($results, $primary = false) { + foreach ($results as $key => $result) { + $results[$key][$this->alias]['name'] = 'Successfuly changed in AfterFind'; + } + return $results; + } } diff --git a/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php b/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php new file mode 100644 index 000000000..b75a2c3aa --- /dev/null +++ b/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php @@ -0,0 +1,52 @@ + + * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * For full copyright and license information, please see the LICENSE.txt + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.Test.Fixture + * @since CakePHP(tm) v 1.2.0.4667 + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ + +/** + * Class PrimaryRelatedFixture + * + * @package Cake.Test.Fixture + */ +class ModelHabtmRelationFixture extends CakeTestFixture { + + /** + * fields property + * + * @var array + */ + public $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'primary_id' => array('type' => 'integer'), + 'related_id' => array('type' => 'integer'), + ); + + /** + * records property + * + * @var array + */ + public $records = array( + array('id' => 1, 'primary_id' => 1, 'related_id' => 1), + array('id' => 2, 'primary_id' => 1, 'related_id' => 2), + array('id' => 3, 'primary_id' => 2, 'related_id' => 1), + array('id' => 4, 'primary_id' => 2, 'related_id' => 2), + ); + +} diff --git a/lib/Cake/Test/Fixture/ModelRelatedFixture.php b/lib/Cake/Test/Fixture/ModelRelatedFixture.php new file mode 100644 index 000000000..94c7c3c42 --- /dev/null +++ b/lib/Cake/Test/Fixture/ModelRelatedFixture.php @@ -0,0 +1,50 @@ + + * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * For full copyright and license information, please see the LICENSE.txt + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.Test.Fixture + * @since CakePHP(tm) v 1.2.0.4667 + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ + +/** + * Class RelatedFixture + * + * @package Cake.Test.Fixture + */ +class ModelRelatedFixture extends CakeTestFixture { + + /** + * fields property + * + * @var array + */ + public $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'name' => array('type' => 'string'), + 'primary_id' => array('type' => 'integer'), + ); + + /** + * records property + * + * @var array + */ + public $records = array( + array('id' => 1, 'name' => 'This should change on afterFind', 'primary_id' => 1), + array('id' => 2, 'name' => 'This also should change on afterFind', 'primary_id' => 2) + ); + +} diff --git a/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php b/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php new file mode 100644 index 000000000..ed7998896 --- /dev/null +++ b/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php @@ -0,0 +1,50 @@ + + * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) + * + * Licensed under The MIT License + * For full copyright and license information, please see the LICENSE.txt + * Redistributions of files must retain the above copyright notice + * + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) + * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests + * @package Cake.Test.Fixture + * @since CakePHP(tm) v 1.2.0.4667 + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ + +/** + * Class PrimaryFixture + * + * @package Cake.Test.Fixture + */ +class ModelWithRelationsFixture extends CakeTestFixture { + + /** + * fields property + * + * @var array + */ + public $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'name' => array('type' => 'string'), + 'related_id' => array('type' => 'integer'), + ); + + /** + * records property + * + * @var array + */ + public $records = array( + array('id' => 1, 'name' => 'First record', 'related_id' => 1), + array('id' => 2, 'name' => 'Second record', 'related_id' => 2) + ); + +} From 4c460c1c6863f9230e5d28d97aced4412d615c63 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 09:52:33 +0200 Subject: [PATCH 07/26] Some tabbing issues --- lib/Cake/Test/Case/Model/ModelReadTest.php | 210 ++++++++++++++++++++- lib/Cake/Test/Case/Model/ModelTestBase.php | 1 + lib/Cake/Test/Case/Model/models.php | 31 +++ 3 files changed, 235 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 807fde84a..e8bacb683 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -6302,7 +6302,6 @@ class ModelReadTest extends BaseModelTest { $this->loadFixtures('User'); $TestModel = new User(); $TestModel->cacheQueries = false; - $TestModel->order = null; $expected = array( 'conditions' => array( @@ -6850,8 +6849,6 @@ class ModelReadTest extends BaseModelTest { )); $this->assertEquals('mariano', $result); - $TestModel->order = null; - $result = $TestModel->field('COUNT(*) AS count', true); $this->assertEquals(4, $result); @@ -6907,9 +6904,7 @@ class ModelReadTest extends BaseModelTest { $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']); $Article = new Article(); - $Article->order = null; $Article->recursive = -1; - $expected = count($Article->find('all', array( 'fields' => array('Article.user_id'), 'group' => 'Article.user_id') @@ -7766,8 +7761,6 @@ class ModelReadTest extends BaseModelTest { )); $this->assertEquals(2, $result['Post']['id']); - $Post->order = null; - $Post->virtualFields = array('other_field' => 'Post.id + 1'); $result = $Post->find('all', array( 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) @@ -7972,5 +7965,208 @@ class ModelReadTest extends BaseModelTest { $result = $Article->find('unPublished'); $this->assertEquals(1, count($result)); } + +/** +* test after find callback on related model +* +* @return void +*/ + public function testRelatedAfterFindCallback() { + $this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation'); + $ModelWithRelations = new ModelWithRelations(); + $ModelWithRelations->bindModel(array( + 'belongsTo' => array( + 'BelongsTo' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'related_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'BelongsTo' => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'BelongsTo' => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail'); + + $ModelWithRelations->bindModel(array( + 'hasOne' => array( + 'HasOne' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'primary_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasOne' => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasOne' => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasOne afterFind callback fail'); + + $ModelWithRelations->bindModel(array( + 'hasMany' => array( + 'HasMany' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'primary_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasMany' => array( + array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasMany' => array( + array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasMany afterFind callback fail'); + + $ModelWithRelations->bindModel(array( + 'hasAndBelongsToMany' => array( + 'HasAndBelongsToMany' => array( + 'className' => 'ModelRelated', + 'with' => 'ModelHabtmRelation', + 'foreignKey' => 'primary_id', + 'associationForeignKey' => 'related_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasAndBelongsToMany' => array( + array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1', + 'ModelHabtmRelation' => array( + 'id' => '1', + 'primary_id' => '1', + 'related_id' => '1' + ) + ), + array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2', + 'ModelHabtmRelation' => array( + 'id' => '2', + 'primary_id' => '1', + 'related_id' => '2' + ) + ) + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasAndBelongsToMany' => array( + array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1', + 'ModelHabtmRelation' => array( + 'id' => '3', + 'primary_id' => '2', + 'related_id' => '1' + ) + ), + array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2', + 'ModelHabtmRelation' => array( + 'id' => '4', + 'primary_id' => '2', + 'related_id' => '2' + ) + ) + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasAndBelongsToMany afterFind callback fail'); + } } diff --git a/lib/Cake/Test/Case/Model/ModelTestBase.php b/lib/Cake/Test/Case/Model/ModelTestBase.php index 16bffd8b4..73ae9c606 100644 --- a/lib/Cake/Test/Case/Model/ModelTestBase.php +++ b/lib/Cake/Test/Case/Model/ModelTestBase.php @@ -72,6 +72,7 @@ abstract class BaseModelTest extends CakeTestCase { 'core.fruits_uuid_tag', 'core.uuid_tag', 'core.product_update_all', 'core.group_update_all', 'core.player', 'core.guild', 'core.guilds_player', 'core.armor', 'core.armors_player', 'core.bidding', 'core.bidding_message', 'core.site', 'core.domain', 'core.domains_site', + 'core.model_with_relations','core.model_related','core.model_habtm_relation', ); /** diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index 1f6c8799b..f91d79a81 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -4993,3 +4993,34 @@ class CustomArticle extends AppModel { } } + +/** + * ModelWithRelations class + * + * @package Cake.Test.Case.Model + */ +class ModelWithRelations extends CakeTestModel { + +} + +/** + * ModelRelated class + * + * @package Cake.Test.Case.Model + */ +class ModelRelated extends CakeTestModel { + + /** + * afterFind callback method + * + * @param array $results + * @param boolean $primary + * @return array Modified $results + */ + public function afterFind($results, $primary = false) { + foreach ($results as $key => $result) { + $results[$key][$this->alias]['name'] = 'Successfuly changed in AfterFind'; + } + return $results; + } +} From 39b202a4a9bf83f859962f8bb7233eceea3944bb Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 10:04:17 +0200 Subject: [PATCH 08/26] Added some tests to related models afterFind callback --- lib/Cake/Test/Case/Model/ModelReadTest.php | 15838 ++++++++-------- lib/Cake/Test/Case/Model/ModelTestBase.php | 127 +- lib/Cake/Test/Case/Model/models.php | 6492 ++++--- .../Fixture/ModelHabtmRelationFixture.php | 42 +- lib/Cake/Test/Fixture/ModelRelatedFixture.php | 38 +- .../Fixture/ModelWithRelationsFixture.php | 38 +- 6 files changed, 11274 insertions(+), 11301 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 6078f1df8..e8bacb683 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -1,5 +1,4 @@ loadFixtures('User'); - $TestModel = new User(); +/** + * testExists function + * @return void + */ + public function testExists() { + $this->loadFixtures('User'); + $TestModel = new User(); - $this->assertTrue($TestModel->exists(1)); + $this->assertTrue($TestModel->exists(1)); - $TestModel->id = 2; - $this->assertTrue($TestModel->exists()); + $TestModel->id = 2; + $this->assertTrue($TestModel->exists()); - $TestModel->delete(); - $this->assertFalse($TestModel->exists()); + $TestModel->delete(); + $this->assertFalse($TestModel->exists()); - $this->assertFalse($TestModel->exists(2)); - } + $this->assertFalse($TestModel->exists(2)); + } - /** - * testFetchingNonUniqueFKJoinTableRecords() - * - * Tests if the results are properly returned in the case there are non-unique FK's - * in the join table but another fields value is different. For example: - * something_id | something_else_id | doomed = 1 - * something_id | something_else_id | doomed = 0 - * Should return both records and not just one. - * - * @return void - */ - public function testFetchingNonUniqueFKJoinTableRecords() { - $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); - $Something = new Something(); +/** + * testFetchingNonUniqueFKJoinTableRecords() + * + * Tests if the results are properly returned in the case there are non-unique FK's + * in the join table but another fields value is different. For example: + * something_id | something_else_id | doomed = 1 + * something_id | something_else_id | doomed = 0 + * Should return both records and not just one. + * + * @return void + */ + public function testFetchingNonUniqueFKJoinTableRecords() { + $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); + $Something = new Something(); - $joinThingData = array( - 'JoinThing' => array( - 'something_id' => 1, - 'something_else_id' => 2, - 'doomed' => '0', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ); + $joinThingData = array( + 'JoinThing' => array( + 'something_id' => 1, + 'something_else_id' => 2, + 'doomed' => '0', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ); - $Something->JoinThing->create($joinThingData); - $Something->JoinThing->save(); + $Something->JoinThing->create($joinThingData); + $Something->JoinThing->save(); - $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); + $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); - $this->assertEquals(true, $result[0]['JoinThing']['doomed']); - $this->assertEquals(false, $result[1]['JoinThing']['doomed']); + $this->assertEquals(true, $result[0]['JoinThing']['doomed']); + $this->assertEquals(false, $result[1]['JoinThing']['doomed']); - $result = $Something->find('first'); + $result = $Something->find('first'); - $this->assertEquals(2, count($result['SomethingElse'])); + $this->assertEquals(2, count($result['SomethingElse'])); - $doomed = Hash::extract($result['SomethingElse'], '{n}.JoinThing.doomed'); - $this->assertTrue(in_array(true, $doomed)); - $this->assertTrue(in_array(false, $doomed)); - } + $doomed = Hash::extract($result['SomethingElse'], '{n}.JoinThing.doomed'); + $this->assertTrue(in_array(true, $doomed)); + $this->assertTrue(in_array(false, $doomed)); + } - /** - * testGroupBy method - * - * These tests will never pass with Postgres or Oracle as all fields in a select must be - * part of an aggregate function or in the GROUP BY statement. - * - * @return void - */ - public function testGroupBy() { - $isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver; - $message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.'; +/** + * testGroupBy method + * + * These tests will never pass with Postgres or Oracle as all fields in a select must be + * part of an aggregate function or in the GROUP BY statement. + * + * @return void + */ + public function testGroupBy() { + $isStrictGroupBy = $this->db instanceof Postgres || $this->db instanceof Sqlite || $this->db instanceof Oracle || $this->db instanceof Sqlserver; + $message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.'; - $this->skipIf($isStrictGroupBy, $message); + $this->skipIf($isStrictGroupBy, $message); - $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); - $Thread = new Thread(); - $Product = new Product(); + $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); + $Thread = new Thread(); + $Product = new Product(); - $result = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'order' => 'Thread.id ASC' + $result = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'order' => 'Thread.id ASC' )); - $expected = array( - array( - 'Thread' => array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1' - ))), - array( - 'Thread' => array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1' - ), - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2' - ), - 'Message' => array( - array( - 'id' => 3, - 'thread_id' => 3, - 'name' => 'Thread 3, Message 1' + $expected = array( + array( + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' + ))), + array( + 'Thread' => array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ), + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1' )))); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'fields' => array('Thread.project_id', 'COUNT(*) AS total') + $rows = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total') )); - $result = array(); - foreach ($rows as $row) { - $result[$row['Thread']['project_id']] = $row[0]['total']; - } - $expected = array( - 1 => 2, - 2 => 1 - ); - $this->assertEquals($expected, $result); + $result = array(); + foreach ($rows as $row) { + $result[$row['Thread']['project_id']] = $row[0]['total']; + } + $expected = array( + 1 => 2, + 2 => 1 + ); + $this->assertEquals($expected, $result); - $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), - 'order' => 'Thread.project_id' + $rows = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), + 'order' => 'Thread.project_id' )); - $result = array(); - foreach ($rows as $row) { - $result[$row['Thread']['project_id']] = $row[0]['total']; - } - $expected = array( - 1 => 2, - 2 => 1 - ); - $this->assertEquals($expected, $result); + $result = array(); + foreach ($rows as $row) { + $result[$row['Thread']['project_id']] = $row[0]['total']; + } + $expected = array( + 1 => 2, + 2 => 1 + ); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'Thread.project_id' + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id' )); - $expected = array( - array( - 'Thread' => array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1' + $expected = array( + array( + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' )))); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'Thread.project_id, Project.id' + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id, Project.id' )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'project_id' + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'project_id' )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('project_id') + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id') )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('project_id', 'Project.id') + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id', 'Project.id') )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('Thread.project_id', 'Project.id') + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('Thread.project_id', 'Project.id') )); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); - $expected = array( - array('Product' => array('type' => 'Clothing'), array('price' => 32)), - array('Product' => array('type' => 'Food'), array('price' => 9)), - array('Product' => array('type' => 'Music'), array('price' => 4)), - array('Product' => array('type' => 'Toy'), array('price' => 3)) - ); - $result = $Product->find('all', array( - 'fields' => array('Product.type', 'MIN(Product.price) as price'), - 'group' => 'Product.type', - 'order' => 'Product.type ASC' - )); - $this->assertEquals($expected, $result); + $expected = array( + array('Product' => array('type' => 'Clothing'), array('price' => 32)), + array('Product' => array('type' => 'Food'), array('price' => 9)), + array('Product' => array('type' => 'Music'), array('price' => 4)), + array('Product' => array('type' => 'Toy'), array('price' => 3)) + ); + $result = $Product->find('all', array( + 'fields' => array('Product.type', 'MIN(Product.price) as price'), + 'group' => 'Product.type', + 'order' => 'Product.type ASC' + )); + $this->assertEquals($expected, $result); - $result = $Product->find('all', array( - 'fields' => array('Product.type', 'MIN(Product.price) as price'), - 'group' => array('Product.type'), - 'order' => 'Product.type ASC')); - $this->assertEquals($expected, $result); - } - - /** - * testOldQuery method - * - * @return void - */ - public function testOldQuery() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); - $Article = new Article(); - - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; - - $results = $Article->query($query); - $this->assertTrue(is_array($results)); - $this->assertEquals(2, count($results)); - - $query = 'SELECT title, body FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; - - $results = $Article->query($query, false); - $this->assertFalse($this->db->getQueryCache($query)); - $this->assertTrue(is_array($results)); - - $query = 'SELECT title, id FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.published = ' . $this->db->value('Y'); - - $results = $Article->query($query, true); - $result = $this->db->getQueryCache($query); - $this->assertFalse(empty($result)); - $this->assertTrue(is_array($results)); - } - - /** - * testPreparedQuery method - * - * @return void - */ - public function testPreparedQuery() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $Article = new Article(); - - $query = 'SELECT title, published FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; - - $params = array(1, 'Y'); - $result = $Article->query($query, $params); - $expected = array( - '0' => array( - $this->db->fullTableName('articles', false, false) => array( - 'title' => 'First Article', 'published' => 'Y') - )); - - if (isset($result[0][0])) { - $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false, false)]; - unset($expected[0][$this->db->fullTableName('articles', false, false)]); + $result = $Product->find('all', array( + 'fields' => array('Product.type', 'MIN(Product.price) as price'), + 'group' => array('Product.type'), + 'order' => 'Product.type ASC')); + $this->assertEquals($expected, $result); } - $this->assertEquals($expected, $result); - $result = $this->db->getQueryCache($query, $params); - $this->assertFalse(empty($result)); +/** + * testOldQuery method + * + * @return void + */ + public function testOldQuery() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); + $Article = new Article(); - $query = 'SELECT id, created FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; - $params = array('First Article'); - $result = $Article->query($query, $params, false); - $this->assertTrue(is_array($result)); - $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false, false)]) || - isset($result[0][0]) - ); - $result = $this->db->getQueryCache($query, $params); - $this->assertTrue(empty($result)); + $results = $Article->query($query); + $this->assertTrue(is_array($results)); + $this->assertEquals(2, count($results)); - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; + $query = 'SELECT title, body FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; - $params = array('%First%'); - $result = $Article->query($query, $params); - $this->assertTrue(is_array($result)); - $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false, false)]['title']) || - isset($result[0][0]['title']) - ); + $results = $Article->query($query, false); + $this->assertFalse($this->db->getQueryCache($query)); + $this->assertTrue(is_array($results)); - //related to ticket #5035 - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; - $params = array('First? Article', 'Y'); - $Article->query($query, $params); + $query = 'SELECT title, id FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ' . $this->db->value('Y'); - $result = $this->db->getQueryCache($query, $params); - $this->assertFalse($result === false); - } + $results = $Article->query($query, true); + $result = $this->db->getQueryCache($query); + $this->assertFalse(empty($result)); + $this->assertTrue(is_array($results)); + } - /** - * testParameterMismatch method - * - * @expectedException PDOException - * @return void - */ - public function testParameterMismatch() { - $this->skipIf($this->db instanceof Sqlite, 'Sqlite does not accept real prepared statements, no way to check this'); - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $Article = new Article(); +/** + * testPreparedQuery method + * + * @return void + */ + public function testPreparedQuery() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $Article = new Article(); - $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; - $params = array('Y'); + $query = 'SELECT title, published FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; - $Article->query($query, $params); - } + $params = array(1, 'Y'); + $result = $Article->query($query, $params); + $expected = array( + '0' => array( + $this->db->fullTableName('articles', false, false) => array( + 'title' => 'First Article', 'published' => 'Y') + )); - /** - * testVeryStrangeUseCase method - * - * @expectedException PDOException - * @return void - */ - public function testVeryStrangeUseCase() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $Article = new Article(); + if (isset($result[0][0])) { + $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false, false)]; + unset($expected[0][$this->db->fullTableName('articles', false, false)]); + } - $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; - $param = array( - $this->db->fullTableName('articles'), - $this->db->fullTableName('articles') . '.user_id', '3', - $this->db->fullTableName('articles') . '.published', 'Y' - ); + $this->assertEquals($expected, $result); + $result = $this->db->getQueryCache($query, $params); + $this->assertFalse(empty($result)); - $Article->query($query, $param); - } + $query = 'SELECT id, created FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; - /** - * testRecursiveUnbind method - * - * @return void - */ - public function testRecursiveUnbind() { - $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); + $params = array('First Article'); + $result = $Article->query($query, $params, false); + $this->assertTrue(is_array($result)); + $this->assertTrue( + isset($result[0][$this->db->fullTableName('articles', false, false)]) || + isset($result[0][0]) + ); + $result = $this->db->getQueryCache($query, $params); + $this->assertTrue(empty($result)); - $this->loadFixtures('Apple', 'Sample'); - $TestModel = new Apple(); - $TestModel->recursive = 2; + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( + $params = array('%First%'); + $result = $Article->query($query, $params); + $this->assertTrue(is_array($result)); + $this->assertTrue( + isset($result[0][$this->db->fullTableName('articles', false, false)]['title']) || + isset($result[0][0]['title']) + ); + + //related to ticket #5035 + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; + $params = array('First? Article', 'Y'); + $Article->query($query, $params); + + $result = $this->db->getQueryCache($query, $params); + $this->assertFalse($result === false); + } + +/** + * testParameterMismatch method + * + * @expectedException PDOException + * @return void + */ + public function testParameterMismatch() { + $this->skipIf($this->db instanceof Sqlite, 'Sqlite does not accept real prepared statements, no way to check this'); + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $Article = new Article(); + + $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; + $params = array('Y'); + + $Article->query($query, $params); + } + +/** + * testVeryStrangeUseCase method + * + * @expectedException PDOException + * @return void + */ + public function testVeryStrangeUseCase() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $Article = new Article(); + + $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; + $param = array( + $this->db->fullTableName('articles'), + $this->db->fullTableName('articles') . '.user_id', '3', + $this->db->fullTableName('articles') . '.published', 'Y' + ); + + $Article->query($query, $param); + } + +/** + * testRecursiveUnbind method + * + * @return void + */ + public function testRecursiveUnbind() { + $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); + + $this->loadFixtures('Apple', 'Sample'); + $TestModel = new Apple(); + $TestModel->recursive = 2; + + $result = $TestModel->find('all'); + $expected = array( array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + )), + 'Child' => array() ), array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), + 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array() + ))), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => + 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array())); + $this->assertEquals($expected, $result); + + $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17'), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', 'modified' => + '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + )), + 'Child' => array() ), array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array() + ))), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array() + )); + + $this->assertEquals($expected, $result); + + $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); + $this->assertTrue($result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', @@ -520,96 +1891,8 @@ class ModelReadTest extends BaseModelTest { 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' ), - 'Sample' => array(), - 'Child' => array( - array( + 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', @@ -617,592 +1900,64 @@ class ModelReadTest extends BaseModelTest { 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' ))), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1' - )), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - )), - 'Child' => array() - ), - array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Sample' => array() - ))), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => - 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array())); - $this->assertEquals($expected, $result); - - $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17'), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', @@ -1211,419 +1966,73 @@ class ModelReadTest extends BaseModelTest { 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' ), - 'Sample' => array(), - 'Child' => array( - array( + 'Parent' => array( 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', 'modified' => - '2006-11-30 18:38:10', - 'mytime' => '22:57:17' + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' ))), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1' - )), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, + 'id' => 3, 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - )), - 'Child' => array() - ), - array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - )), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( 'id' => 5, 'apple_id' => 5, 'color' => 'Green', @@ -1632,6511 +2041,6132 @@ class ModelReadTest extends BaseModelTest { 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17' - ))))), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17', + ), 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Sample' => array() - ))), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ), - 'Child' => array() - )); - - $this->assertEquals($expected, $result); - - $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); - $this->assertTrue($result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ))); - - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); - $this->assertTrue($result); - - $result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - )), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1' - )), - array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - )), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - )), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent'))); - $this->assertTrue($result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Apple' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17', - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2', - 'Apple' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 1, - 'apple_id' => 3, - 'name' => 'sample1', - 'Apple' => array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 2, - 'apple_id' => 1, - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 2, - 'apple_id' => 2, - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => 1, - 'apple_id' => 2, - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => 3, - 'apple_id' => 2, - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3', - 'Apple' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => - '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => 4, - 'apple_id' => 5, - 'name' => 'sample4', - 'Apple' => array( - 'id' => 5, - 'apple_id' => 5, - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17'), - 'Parent' => array( - 'id' => 4, - 'apple_id' => 2, - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17', - 'Sample' => array( - 'id' => 3, - 'apple_id' => 4, - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - )), - array( - 'Apple' => array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => 6, - 'apple_id' => 4, - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17', - 'Sample' => array(), - 'Child' => array( - array( - 'id' => 7, - 'apple_id' => 6, - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', 'modified' => - '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - 'Sample' => array( - 'id' => '', - 'apple_id' => '', - 'name' => '' - ))); - $this->assertEquals($expected, $result); - } - - /** - * testSelfAssociationAfterFind method - * - * @return void - */ - public function testSelfAssociationAfterFind() { - $this->loadFixtures('Apple', 'Sample'); - $afterFindModel = new NodeAfterFind(); - $afterFindModel->recursive = 3; - $afterFindData = $afterFindModel->find('all'); - - $duplicateModel = new NodeAfterFind(); - $duplicateModel->recursive = 3; - - $noAfterFindModel = new NodeNoAfterFind(); - $noAfterFindModel->recursive = 3; - $noAfterFindData = $noAfterFindModel->find('all'); - - $this->assertFalse($afterFindModel == $noAfterFindModel); - $this->assertEquals($afterFindData, $noAfterFindData); - } - - /** - * Test that afterFind can completely unset data. - * - * @return void - */ - public function testAfterFindUnset() { - $this->loadFixtures('Article', 'Comment', 'User'); - $model = new CustomArticle(); - $model->bindModel(array( - 'hasMany' => array( - 'ModifiedComment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ) - )); - $model->ModifiedComment->remove = true; - $result = $model->find('all'); - $this->assertTrue( - empty($result[0]['ModifiedComment']), 'Zeroith row should be removed by afterFind' - ); - } - - /** - * testFindThreadedNoParent method - * - * @return void - */ - public function testFindThreadedNoParent() { - $this->loadFixtures('Apple', 'Sample'); - $Apple = new Apple(); - $result = $Apple->find('threaded'); - $result = Hash::extract($result, '{n}.children'); - $expected = array(array(), array(), array(), array(), array(), array(), array()); - $this->assertEquals($expected, $result); - } - - /** - * testFindThreaded method - * - * @return void - */ - public function testFindThreaded() { - $this->loadFixtures('Person'); - $Model = new Person(); - $Model->recursive = -1; - $result = $Model->find('threaded'); - $result = Hash::extract($result, '{n}.children'); - $expected = array(array(), array(), array(), array(), array(), array(), array()); - $this->assertEquals($expected, $result); - - $result = $Model->find('threaded', array('parent' => 'mother_id')); - $expected = array( - array( - 'Person' => array( - 'id' => '4', - 'name' => 'mother - grand mother', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array( - array( - 'Person' => array( - 'id' => '2', - 'name' => 'mother', - 'mother_id' => '4', - 'father_id' => '5' - ), - 'children' => array( - array( - 'Person' => array( - 'id' => '1', - 'name' => 'person', - 'mother_id' => '2', - 'father_id' => '3' + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' ), - 'children' => array() - ) - ) - ) - ) - ), - array( - 'Person' => array( - 'id' => '5', - 'name' => 'mother - grand father', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array() - ), - array( - 'Person' => array( - 'id' => '6', - 'name' => 'father - grand mother', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array( - array( - 'Person' => array( - 'id' => '3', - 'name' => 'father', - 'mother_id' => '6', - 'father_id' => '7' - ), - 'children' => array() - ) - ) - ), - array( - 'Person' => array( - 'id' => '7', - 'name' => 'father - grand father', - 'mother_id' => '0', - 'father_id' => '0' - ), - 'children' => array() - ) - ); - $this->assertEquals($expected, $result); - } - - /** - * testFindAllThreaded method - * - * @return void - */ - public function testFindAllThreaded() { - $this->loadFixtures('Category'); - $TestModel = new Category(); - - $result = $TestModel->find('threaded'); - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 1%') - )); - - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name' - )); - - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array('order' => 'id DESC')); - - $expected = array( - array( - 'Category' => array( - 'id' => 5, - 'parent_id' => 0, - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => 4, - 'parent_id' => 0, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => 3, - 'parent_id' => 1, - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 3%') - )); - $expected = array( - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 1.1%') - )); - $expected = array( - array('Category' => + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name', - 'conditions' => array('Category.id !=' => 2) - )); - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'fields' => 'id, name, parent_id', - 'conditions' => array('Category.id !=' => 1) - )); - $expected = array( - array('Category' => array( - 'id' => '2', - 'name' => 'Category 1.1', - 'parent_id' => '1' - )), - array('Category' => array( - 'id' => '3', - 'name' => 'Category 1.2', - 'parent_id' => '1' - )), - array('Category' => array( - 'id' => '4', - 'name' => 'Category 2', - 'parent_id' => '0' - )), - array('Category' => array( - 'id' => '5', - 'name' => 'Category 3', - 'parent_id' => '0' - )), - array('Category' => array( - 'id' => '6', - 'name' => 'Category 3.1', - 'parent_id' => '5' - )), - array('Category' => array( - 'id' => '7', - 'name' => 'Category 1.1.1', - 'parent_id' => '2' - )), - array('Category' => array( - 'id' => '8', - 'name' => 'Category 1.1.2', - 'parent_id' => '2' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name', - 'conditions' => array('Category.id !=' => 1) - )); - $expected = array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ); - $this->assertEquals($expected, $result); - } - - /** - * test find('neighbors') - * - * @return void - */ - public function testFindNeighbors() { - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); - $TestModel = new Article(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('fields' => array('id'))); - - $this->assertNull($result['prev']); - $this->assertEquals(array('id' => 2), $result['next']['Article']); - $this->assertEquals(2, count($result['next']['Comment'])); - $this->assertEquals(2, count($result['next']['Tag'])); - - $TestModel->id = 2; - $TestModel->recursive = 0; - $result = $TestModel->find('neighbors', array( - 'fields' => array('id') - )); - - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1 - )), - 'next' => array( - 'Article' => array( - 'id' => 3 - ))); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $TestModel->recursive = 1; - $result = $TestModel->find('neighbors', array('fields' => array('id'))); - - $this->assertNull($result['next']); - $this->assertEquals(array('id' => 2), $result['prev']['Article']); - $this->assertEquals(2, count($result['prev']['Comment'])); - $this->assertEquals(2, count($result['prev']['Tag'])); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => null, - 'next' => array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ) - ); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - 'next' => array( - 'Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ) - ) - ); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ), - 'next' => null - ); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 0; - $TestModel->id = 1; - $one = $TestModel->read(); - $TestModel->id = 2; - $two = $TestModel->read(); - $TestModel->id = 3; - $three = $TestModel->read(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => null, 'next' => $two); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => $one, 'next' => $three); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => $two, 'next' => null); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 2; - $TestModel->id = 1; - $one = $TestModel->read(); - $TestModel->id = 2; - $two = $TestModel->read(); - $TestModel->id = 3; - $three = $TestModel->read(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => null, 'next' => $two); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => $one, 'next' => $three); - $this->assertEquals($expected, $result); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => $two, 'next' => null); - $this->assertEquals($expected, $result); - } - - /** - * Test find(neighbors) with missing fields so no neighbors are found. - * - * @return void - */ - public function testFindNeighborsNoPrev() { - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); - $Article = new Article(); - - $result = $Article->find('neighbors', array( - 'field' => 'Article.title', - 'value' => 'Second Article', - 'fields' => array('id'), - 'conditions' => array( - 'Article.title LIKE' => '%Article%' - ), - 'recursive' => 0, - )); - $expected = array( - 'prev' => null, - 'next' => null - ); - $this->assertEquals($expected, $result); - } - - /** - * testFindCombinedRelations method - * - * @return void - */ - public function testFindCombinedRelations() { - $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); - - $this->loadFixtures('Apple', 'Sample'); - $TestModel = new Apple(); - - $result = $TestModel->find('all'); - - $expected = array( - array( - 'Apple' => array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array( - array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '2', - 'apple_id' => '2', - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => '3', - 'apple_id' => '2', - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '3', - 'apple_id' => '2', - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '1', - 'apple_id' => '3', - 'name' => 'sample1' - ), - 'Child' => array() - ), - array( - 'Apple' => array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '3', - 'apple_id' => '4', - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '4', - 'apple_id' => '5', - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array( - array( - 'id' => '7', - 'apple_id' => '6', - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '7', - 'apple_id' => '6', - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array() - )); - $this->assertEquals($expected, $result); - } - - /** - * testSaveEmpty method - * - * @return void - */ - public function testSaveEmpty() { - $this->loadFixtures('Thread'); - $TestModel = new Thread(); - $data = array(); - $expected = $TestModel->save($data); - $this->assertFalse($expected); - } - - /** - * testFindAllWithConditionInChildQuery - * - * @return void - */ - public function testFindAllWithConditionInChildQuery() { - $this->loadFixtures('Basket', 'FilmFile'); - - $TestModel = new Basket(); - $recursive = 3; - $result = $TestModel->find('all', compact('recursive')); - - $expected = array( - array( - 'Basket' => array( - 'id' => 1, - 'type' => 'nonfile', - 'name' => 'basket1', - 'object_id' => 1, - 'user_id' => 1, - ), - 'FilmFile' => array( - 'id' => '', - 'name' => '', - ) - ), - array( - 'Basket' => array( - 'id' => 2, - 'type' => 'file', - 'name' => 'basket2', - 'object_id' => 2, - 'user_id' => 1, - ), - 'FilmFile' => array( - 'id' => 2, - 'name' => 'two', - ) - ), - ); - $this->assertEquals($expected, $result); - } - - /** - * testFindAllWithConditionsHavingMixedDataTypes method - * - * @return void - */ - public function testFindAllWithConditionsHavingMixedDataTypes() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); - $TestModel = new Article(); - $expected = array( - array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ) - ); - $conditions = array('id' => array('1', 2)); - $recursive = -1; - $order = 'Article.id ASC'; - $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); - $this->assertEquals($expected, $result); - - $this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.'); - - $conditions = array('id' => array('1', 2, '3.0')); - $order = 'Article.id ASC'; - $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); - $expected = array( - array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ), - array( - 'Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ) - ) - ); - $this->assertEquals($expected, $result); - } - - /** - * testBindUnbind method - * - * @return void - */ - public function testBindUnbind() { - $this->loadFixtures( - 'User', 'Comment', 'FeatureSet', 'DeviceType', 'DeviceTypeCategory', 'ExteriorTypeCategory', 'Device', 'Document', 'DocumentDirectory' - ); - $TestModel = new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEquals($expected, $result); - - $TestModel->resetAssociations(); - $result = $TestModel->hasMany; - $this->assertSame(array(), $result); - - $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEquals($expected, $result); - - $result = $TestModel->hasMany; - $expected = array( - 'Comment' => array( - 'className' => 'Comment', - 'foreignKey' => 'user_id', - 'conditions' => null, - 'fields' => null, - 'order' => null, - 'limit' => null, - 'offset' => null, - 'dependent' => null, - 'exclusive' => null, - 'finderQuery' => null, - 'counterQuery' => null - )); - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); - $this->assertTrue($result); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => - 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEquals($expected, $result); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array('hasMany' => array( - 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user', - 'order' => array('User.id' => 'ASC'), - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEquals($expected, $result); - - $TestModel2 = new DeviceType(); - - $expected = array( - 'className' => 'FeatureSet', - 'foreignKey' => 'feature_set_id', - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'counterCache' => '' - ); - $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); - - $TestModel2->bindModel(array( - 'belongsTo' => array( - 'FeatureSet' => array( - 'className' => 'FeatureSet', - 'conditions' => array('active' => true) - ) - ) - )); - $expected['conditions'] = array('active' => true); - $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); - - $TestModel2->bindModel(array( - 'belongsTo' => array( - 'FeatureSet' => array( - 'className' => 'FeatureSet', - 'foreignKey' => false, - 'conditions' => array('Feature.name' => 'DeviceType.name') - ) - ) - )); - $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); - $expected['foreignKey'] = false; - $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); - - $TestModel2->bindModel(array( - 'hasMany' => array( - 'NewFeatureSet' => array( - 'className' => 'FeatureSet', - 'conditions' => array('active' => true) - ) - ) - )); - - $expected = array( - 'className' => 'FeatureSet', - 'conditions' => array('active' => true), - 'foreignKey' => 'device_type_id', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'dependent' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ); - $this->assertEquals($expected, $TestModel2->hasMany['NewFeatureSet']); - $this->assertTrue(is_object($TestModel2->NewFeatureSet)); - } - - /** - * testBindMultipleTimes method - * - * @return void - */ - public function testBindMultipleTimes() { - $this->loadFixtures('User', 'Comment', 'Article', 'Tag', 'ArticlesTag'); - $TestModel = new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array( - 'hasMany' => array( - 'Items' => array('className' => 'Comment') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Items' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Items' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Items' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Items' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array( - 'hasMany' => array( - 'Items' => array('className' => 'Article') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Items' => array( - array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Items' => array() - ), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Items' => array( - array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Items' => array() - )); - - $this->assertEquals($expected, $result); - } - - /** - * test that multiple reset = true calls to bindModel() result in the original associations. - * - * @return void - */ - public function testBindModelMultipleTimesResetCorrectly() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new User(); - - $TestModel->bindModel(array('hasMany' => array('Comment'))); - $TestModel->bindModel(array('hasMany' => array('Comment'))); - $TestModel->resetAssociations(); - - $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind'); - } - - /** - * testBindMultipleTimes method with different reset settings - * - * @return void - */ - public function testBindMultipleTimesWithDifferentResetSettings() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array( - 'hasMany' => array('Comment') - )); - $this->assertTrue($result); - $result = $TestModel->bindModel( - array('hasMany' => array('Article')), false - ); - $this->assertTrue($result); - - $result = array_keys($TestModel->hasMany); - $expected = array('Comment', 'Article'); - $this->assertEquals($expected, $result); - - $TestModel->resetAssociations(); - - $result = array_keys($TestModel->hasMany); - $expected = array('Article'); - $this->assertEquals($expected, $result); - } - - /** - * test that bindModel behaves with Custom primary Key associations - * - * @return void - */ - public function testBindWithCustomPrimaryKey() { - $this->loadFixtures('Story', 'StoriesTag', 'Tag'); - $Model = ClassRegistry::init('StoriesTag'); - $Model->bindModel(array( - 'belongsTo' => array( - 'Tag' => array( - 'className' => 'Tag', - 'foreignKey' => 'story' - )))); - - $result = $Model->find('all'); - $this->assertFalse(empty($result)); - } - - /** - * test that calling unbindModel() with reset == true multiple times - * leaves associations in the correct state. - * - * @return void - */ - public function testUnbindMultipleTimesResetCorrectly() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new Article10(); - - $TestModel->unbindModel(array('hasMany' => array('Comment'))); - $TestModel->unbindModel(array('hasMany' => array('Comment'))); - $TestModel->resetAssociations(); - - $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed'); - } - - /** - * testBindMultipleTimes method with different reset settings - * - * @return void - */ - public function testUnBindMultipleTimesWithDifferentResetSettings() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel = new Comment(); - - $result = array_keys($TestModel->belongsTo); - $expected = array('Article', 'User'); - $this->assertEquals($expected, $result); - - $result = $TestModel->unbindModel(array( - 'belongsTo' => array('User') - )); - $this->assertTrue($result); - $result = $TestModel->unbindModel( - array('belongsTo' => array('Article')), false - ); - $this->assertTrue($result); - - $result = array_keys($TestModel->belongsTo); - $expected = array(); - $this->assertEquals($expected, $result); - - $TestModel->resetAssociations(); - - $result = array_keys($TestModel->belongsTo); - $expected = array('User'); - $this->assertEquals($expected, $result); - } - - /** - * testAssociationAfterFind method - * - * @return void - */ - public function testAssociationAfterFind() { - $this->loadFixtures('Post', 'Author', 'Comment'); - $TestModel = new Post(); - $result = $TestModel->find('all', array( - 'order' => array('Post.id' => 'ASC') - )); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - )), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31', - 'test' => 'working' - )), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - ))); - $this->assertEquals($expected, $result); - unset($TestModel); - - $Author = new Author(); - $Author->Post->bindModel(array( - 'hasMany' => array( - 'Comment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ))); - $result = $Author->find('all', array( - 'conditions' => array('Author.id' => 1), - 'order' => array('Author.id' => 'ASC'), - 'recursive' => 2 - )); - $expected = array( - 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31', - 'callback' => 'Fire' - ); - $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); - } - - /** - * testDeeperAssociationAfterFind method - * - * @return void - */ - public function testDeeperAssociationAfterFind() { - $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article'); - - $Post = new Post(); - $Post->bindModel(array( - 'hasMany' => array( - 'Comment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ))); - $Post->Comment->bindModel(array( - 'hasOne' => array( - 'Attachment' => array( - 'className' => 'ModifiedAttachment', - ) - ))); - - $result = $Post->find('first', array( - 'conditions' => array('Post.id' => 2), - 'recursive' => 2 - )); - $this->assertTrue(isset($result['Comment'][0]['callback'])); - $this->assertEquals('Fire', $result['Comment'][0]['callback']); - $this->assertTrue(isset($result['Comment'][0]['Attachment']['callback'])); - $this->assertEquals('Fired', $result['Comment'][0]['Attachment']['callback']); - } - - /** - * Tests that callbacks can be properly disabled - * - * @return void - */ - public function testCallbackDisabling() { - $this->loadFixtures('Author'); - $TestModel = new ModifiedAuthor(); - - $result = Hash::extract($TestModel->find('all'), '{n}.Author.user'); - $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); - $this->assertEquals($expected, $result); - - $result = Hash::extract($TestModel->find('all', array('callbacks' => 'after')), '{n}.Author.user'); - $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); - $this->assertEquals($expected, $result); - - $result = Hash::extract($TestModel->find('all', array('callbacks' => 'before')), '{n}.Author.user'); - $expected = array('mariano', 'nate', 'larry', 'garrett'); - $this->assertEquals($expected, $result); - - $result = Hash::extract($TestModel->find('all', array('callbacks' => false)), '{n}.Author.user'); - $expected = array('mariano', 'nate', 'larry', 'garrett'); - $this->assertEquals($expected, $result); - } - - /** - * testAssociationAfterFindCallbacksDisabled method - * - * @return void - */ - public function testAssociationAfterFindCalbacksDisabled() { - $this->loadFixtures('Post', 'Author', 'Comment'); - $TestModel = new Post(); - $result = $TestModel->find('all', array( - 'callbacks' => false, - 'order' => array('Post.id' => 'ASC'), - )); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ))); - $this->assertEquals($expected, $result); - unset($TestModel); - - $Author = new Author(); - $Author->Post->bindModel(array( - 'hasMany' => array( - 'Comment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ))); - $result = $Author->find('all', array( - 'conditions' => array('Author.id' => 1), - 'recursive' => 2, - 'order' => array('Author.id' => 'ASC'), - 'callbacks' => false - )); - $expected = array( - 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ); - $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); - } - - /** - * Tests that the database configuration assigned to the model can be changed using - * (before|after)Find callbacks - * - * @return void - */ - public function testCallbackSourceChange() { - $this->loadFixtures('Post'); - $TestModel = new Post(); - $this->assertEquals(3, count($TestModel->find('all'))); - } - - /** - * testCallbackSourceChangeUnknownDatasource method - * - * @expectedException MissingDatasourceConfigException - * @return void - */ - public function testCallbackSourceChangeUnknownDatasource() { - $this->loadFixtures('Post', 'Author'); - $TestModel = new Post(); - $this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); - } - - /** - * testMultipleBelongsToWithSameClass method - * - * @return void - */ - public function testMultipleBelongsToWithSameClass() { - $this->loadFixtures( - 'DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory' - ); - - $DeviceType = new DeviceType(); - - $DeviceType->recursive = 2; - $result = $DeviceType->read(null, 1); - - $expected = array( - 'DeviceType' => array( - 'id' => 1, - 'device_type_category_id' => 1, - 'feature_set_id' => 1, - 'exterior_type_category_id' => 1, - 'image_id' => 1, - 'extra1_id' => 1, - 'extra2_id' => 1, - 'name' => 'DeviceType 1', - 'order' => 0 - ), - 'Image' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'Extra1' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'Extra2' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'DeviceTypeCategory' => array( - 'id' => 1, - 'name' => 'DeviceTypeCategory 1' - ), - 'FeatureSet' => array( - 'id' => 1, - 'name' => 'FeatureSet 1' - ), - 'ExteriorTypeCategory' => array( - 'id' => 1, - 'image_id' => 1, - 'name' => 'ExteriorTypeCategory 1', - 'Image' => array( - 'id' => 1, - 'device_type_id' => 1, - 'name' => 'Device 1', - 'typ' => 1 - )), - 'Device' => array( - array( - 'id' => 1, - 'device_type_id' => 1, - 'name' => 'Device 1', - 'typ' => 1 - ), - array( - 'id' => 2, - 'device_type_id' => 1, - 'name' => 'Device 2', - 'typ' => 1 - ), - array( - 'id' => 3, - 'device_type_id' => 1, - 'name' => 'Device 3', - 'typ' => 2 - ))); - - $this->assertEquals($expected, $result); - } - - /** - * testHabtmRecursiveBelongsTo method - * - * @return void - */ - public function testHabtmRecursiveBelongsTo() { - $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); - $Portfolio = new Portfolio(); - - $result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3)); - $expected = array( - 'Portfolio' => array( - 'id' => 2, - 'seller_id' => 1, - 'name' => 'Portfolio 2' - ), - 'Item' => array( - array( - 'id' => 2, - 'syfile_id' => 2, - 'published' => false, - 'name' => 'Item 2', - 'ItemsPortfolio' => array( - 'id' => 2, - 'item_id' => 2, - 'portfolio_id' => 2 - ), - 'Syfile' => array( - 'id' => 2, - 'image_id' => 2, - 'name' => 'Syfile 2', - 'item_count' => null, - 'Image' => array( - 'id' => 2, - 'name' => 'Image 2' - ) + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' )), array( - 'id' => 6, - 'syfile_id' => 6, - 'published' => false, - 'name' => 'Item 6', - 'ItemsPortfolio' => array( - 'id' => 6, - 'item_id' => 6, - 'portfolio_id' => 2 - ), - 'Syfile' => array( - 'id' => 6, - 'image_id' => null, - 'name' => 'Syfile 6', - 'item_count' => null, - 'Image' => array() - )))); - - $this->assertEquals($expected, $result); - } - - /** - * testNonNumericHabtmJoinKey method - * - * @return void - */ - public function testNonNumericHabtmJoinKey() { - $this->loadFixtures('Post', 'Tag', 'PostsTag', 'Author'); - $Post = new Post(); - $Post->bindModel(array( - 'hasAndBelongsToMany' => array('Tag') - )); - $Post->Tag->primaryKey = 'tag'; - - $result = $Post->find('all', array( - 'order' => 'Post.id ASC', - )); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => 1, - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => 3, - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31', - 'test' => 'working' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => 1, - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - ), - 'Tag' => array() - )); - $this->assertEquals($expected, $result); - } - - /** - * testHabtmFinderQuery method - * - * @return void - */ - public function testHabtmFinderQuery() { - $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); - $Article = new Article(); - - $sql = $this->db->buildStatement( - array( - 'fields' => $this->db->fields($Article->Tag, null, array( - 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id' - )), - 'table' => $this->db->fullTableName('tags'), - 'alias' => 'Tag', - 'limit' => null, - 'offset' => null, - 'group' => null, - 'joins' => array(array( - 'alias' => 'ArticlesTag', - 'table' => 'articles_tags', - 'conditions' => array( - array("ArticlesTag.article_id" => '{$__cakeID__$}'), - array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) - ) - )), - 'conditions' => array(), - 'order' => null - ), $Article - ); - - $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; - $result = $Article->find('first'); - $expected = array( - array( - 'id' => '1', - 'tag' => 'tag1' - ), - array( - 'id' => '2', - 'tag' => 'tag2' - )); - - $this->assertEquals($expected, $result['Tag']); - } - - /** - * testHabtmLimitOptimization method - * - * @return void - */ - public function testHabtmLimitOptimization() { - $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); - $TestModel = new Article(); - - $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; - $result = $TestModel->read(null, 2); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - - $this->assertEquals($expected, $result); - - $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1; - $result = $TestModel->read(null, 2); - unset($expected['Tag'][1]); - - $this->assertEquals($expected, $result); - } - - /** - * testHasManyLimitOptimization method - * - * @return void - */ - public function testHasManyLimitOptimization() { - $this->loadFixtures('Project', 'Thread', 'Message', 'Bid'); - $Project = new Project(); - $Project->recursive = 3; - - $result = $Project->find('all', array( - 'order' => 'Project.id ASC', - )); - $expected = array( - array( - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1', - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1', - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' ), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2' - ))), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1', - 'Bid' => array( - 'id' => 1, - 'message_id' => 1, - 'name' => 'Bid 1.1' - )))), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2', - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1', - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); + + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); + $this->assertTrue($result); + + $result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' ), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2' - ))), - 'Message' => array( - array( - 'id' => 2, - 'thread_id' => 2, - 'name' => 'Thread 2, Message 1', - 'Bid' => array( - 'id' => 4, - 'message_id' => 2, - 'name' => 'Bid 2.1' - )))))), - array( - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2' - ), - 'Thread' => array( - array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1', - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2', - 'Thread' => array( - array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1' - ))), - 'Message' => array( - array( - 'id' => 3, - 'thread_id' => 3, - 'name' => 'Thread 3, Message 1', - 'Bid' => array( - 'id' => 3, - 'message_id' => 3, - 'name' => 'Bid 3.1' - )))))), - array( - 'Project' => array( - 'id' => 3, - 'name' => 'Project 3' - ), - 'Thread' => array() - )); - - $this->assertEquals($expected, $result); - } - - /** - * testFindAllRecursiveSelfJoin method - * - * @return void - */ - public function testFindAllRecursiveSelfJoin() { - $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement'); - $TestModel = new Home(); - $TestModel->recursive = 2; - - $result = $TestModel->find('all', array( - 'order' => 'Home.id ASC', - )); - $expected = array( - array( - 'Home' => array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'AnotherArticle' => array( - 'id' => '1', - 'title' => 'First Article', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ))), - 'Advertisement' => array( - 'id' => '1', - 'title' => 'First Ad', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + )), array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + )), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + )), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent'))); + $this->assertTrue($result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => + '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17'), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', 'modified' => + '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); + $this->assertEquals($expected, $result); + } + +/** + * testSelfAssociationAfterFind method + * + * @return void + */ + public function testSelfAssociationAfterFind() { + $this->loadFixtures('Apple', 'Sample'); + $afterFindModel = new NodeAfterFind(); + $afterFindModel->recursive = 3; + $afterFindData = $afterFindModel->find('all'); + + $duplicateModel = new NodeAfterFind(); + $duplicateModel->recursive = 3; + + $noAfterFindModel = new NodeNoAfterFind(); + $noAfterFindModel->recursive = 3; + $noAfterFindData = $noAfterFindModel->find('all'); + + $this->assertFalse($afterFindModel == $noAfterFindModel); + $this->assertEquals($afterFindData, $noAfterFindData); + } + +/** + * Test that afterFind can completely unset data. + * + * @return void + */ + public function testAfterFindUnset() { + $this->loadFixtures('Article', 'Comment', 'User'); + $model = new CustomArticle(); + $model->bindModel(array( + 'hasMany' => array( + 'ModifiedComment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ) + )); + $model->ModifiedComment->remove = true; + $result = $model->find('all'); + $this->assertTrue( + empty($result[0]['ModifiedComment']), + 'Zeroith row should be removed by afterFind' + ); + } + +/** + * testFindThreadedNoParent method + * + * @return void + */ + public function testFindThreadedNoParent() { + $this->loadFixtures('Apple', 'Sample'); + $Apple = new Apple(); + $result = $Apple->find('threaded'); + $result = Hash::extract($result, '{n}.children'); + $expected = array(array(), array(), array(), array(), array(), array(), array()); + $this->assertEquals($expected, $result); + } + +/** + * testFindThreaded method + * + * @return void + */ + public function testFindThreaded() { + $this->loadFixtures('Person'); + $Model = new Person(); + $Model->recursive = -1; + $result = $Model->find('threaded'); + $result = Hash::extract($result, '{n}.children'); + $expected = array(array(), array(), array(), array(), array(), array(), array()); + $this->assertEquals($expected, $result); + + $result = $Model->find('threaded', array('parent' => 'mother_id')); + $expected = array( + array( + 'Person' => array( + 'id' => '4', + 'name' => 'mother - grand mother', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array( + array( + 'Person' => array( + 'id' => '2', + 'name' => 'mother', + 'mother_id' => '4', + 'father_id' => '5' + ), + 'children' => array( + array( + 'Person' => array( + 'id' => '1', + 'name' => 'person', + 'mother_id' => '2', + 'father_id' => '3' + ), + 'children' => array() + ) + ) + ) + ) ), array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - )))), - array( - 'Home' => array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'AnotherArticle' => array( - 'id' => '3', - 'title' => 'Third Article', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31', - 'Home' => array( - array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))), - 'Advertisement' => array( - 'id' => '1', - 'title' => 'First Ad', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( - array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' + 'Person' => array( + 'id' => '5', + 'name' => 'mother - grand father', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array() ), array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))))); + 'Person' => array( + 'id' => '6', + 'name' => 'father - grand mother', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array( + array( + 'Person' => array( + 'id' => '3', + 'name' => 'father', + 'mother_id' => '6', + 'father_id' => '7' + ), + 'children' => array() + ) + ) + ), + array( + 'Person' => array( + 'id' => '7', + 'name' => 'father - grand father', + 'mother_id' => '0', + 'father_id' => '0' + ), + 'children' => array() + ) + ); + $this->assertEquals($expected, $result); + } - $this->assertEquals($expected, $result); - } +/** + * testFindAllThreaded method + * + * @return void + */ + public function testFindAllThreaded() { + $this->loadFixtures('Category'); + $TestModel = new Category(); - /** - * testFindAllRecursiveWithHabtm method - * - * @return void - */ - public function testFindAllRecursiveWithHabtm() { - $this->loadFixtures( - 'MyCategoriesMyUsers', 'MyCategoriesMyProducts', 'MyCategory', 'MyUser', 'MyProduct' - ); + $result = $TestModel->find('threaded'); + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); - $MyUser = new MyUser(); - $MyUser->recursive = 2; - - $result = $MyUser->find('all', array( - 'order' => 'MyUser.id ASC' + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1%') )); - $expected = array( - array( - 'MyUser' => array('id' => '1', 'firstname' => 'userA'), - 'MyCategory' => array( - array( - 'id' => '1', - 'name' => 'A', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ))), - array( - 'id' => '3', - 'name' => 'C', - 'MyProduct' => array( - array( - 'id' => '2', - 'name' => 'computer' - ))))), - array( - 'MyUser' => array( - 'id' => '2', - 'firstname' => 'userB' - ), - 'MyCategory' => array( - array( - 'id' => '1', - 'name' => 'A', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ))), - array( - 'id' => '2', - 'name' => 'B', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ), - array( - 'id' => '2', - 'name' => 'computer' - )))))); - $this->assertEquals($expected, $result); - } + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); - /** - * testReadFakeThread method - * - * @return void - */ - public function testReadFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel = new CategoryThread(); + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name' + )); - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $TestModel->id = 7; - $result = $TestModel->read(); - $expected = array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))))))); + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); - $this->db->fullDebug = $fullDebug; - $this->assertEquals($expected, $result); - } + $result = $TestModel->find('threaded', array('order' => 'id DESC')); - /** - * testFindFakeThread method - * - * @return void - */ - public function testFindFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel = new CategoryThread(); - - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7))); - - $expected = array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))))))); - - $this->db->fullDebug = $fullDebug; - $this->assertEquals($expected, $result); - } - - /** - * testFindAllFakeThread method - * - * @return void - */ - public function testFindAllFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel = new CategoryThread(); - - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $result = $TestModel->find('all'); - $expected = array( - array( - 'CategoryThread' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => null, - 'parent_id' => null, - 'name' => null, - 'created' => null, - 'updated' => null, - 'ParentCategory' => array() - )), - array( - 'CategoryThread' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )), - array( - 'CategoryThread' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - ))), - array( - 'CategoryThread' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )))), - array( - 'CategoryThread' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - ))))), - array( - 'CategoryThread' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )))))), - array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( + $expected = array( + array( + 'Category' => array( + 'id' => 5, + 'parent_id' => 0, + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => 4, + 'parent_id' => 0, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31' - )))))))); + ), + 'children' => array( + array( + 'Category' => array( + 'id' => 3, + 'parent_id' => 1, + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ) + ) + ) + ); + $this->assertEquals($expected, $result); - $this->db->fullDebug = $fullDebug; - $this->assertEquals($expected, $result); - } - - /** - * testConditionalNumerics method - * - * @return void - */ - public function testConditionalNumerics() { - $this->loadFixtures('NumericArticle'); - $NumericArticle = new NumericArticle(); - $data = array('conditions' => array('title' => '12345abcde')); - $result = $NumericArticle->find('first', $data); - $this->assertTrue(!empty($result)); - - $data = array('conditions' => array('title' => '12345')); - $result = $NumericArticle->find('first', $data); - $this->assertTrue(empty($result)); - } - - /** - * test buildQuery() - * - * @return void - */ - public function testBuildQuery() { - $this->loadFixtures('User'); - $TestModel = new User(); - $TestModel->cacheQueries = false; - $TestModel->order = null; - - $expected = array( - 'conditions' => array( - 'user' => 'larry' - ), - 'fields' => null, - 'joins' => array(), - 'limit' => null, - 'offset' => null, - 'order' => array( - 0 => null - ), - 'page' => 1, - 'group' => null, - 'callbacks' => true, - 'returnQuery' => true - ); - $result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry'))); - $this->assertEquals($expected, $result); - } - - /** - * test find('all') method - * - * @return void - */ - public function testFindAll() { - $this->loadFixtures('User'); - $TestModel = new User(); - $TestModel->cacheQueries = false; - - $result = $TestModel->find('all'); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('conditions' => 'User.id > 2')); - $expected = array( - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%') + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 3%') )); - $expected = array( - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('conditions' => array('User.id' => '0'))); - $expected = array(); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array( - 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%') - ))); - - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - )), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC')); - $expected = array( - array('User' => array('user' => 'garrett')), - array('User' => array('user' => 'larry')), - array('User' => array('user' => 'mariano')), - array('User' => array('user' => 'nate'))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC')); - $expected = array( - array('User' => array('user' => 'nate')), - array('User' => array('user' => 'mariano')), - array('User' => array('user' => 'larry')), - array('User' => array('user' => 'garrett'))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('limit' => 3, 'page' => 1)); - - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ))); - $this->assertEquals($expected, $result); - - $ids = array(4 => 1, 5 => 3); - $result = $TestModel->find('all', array( - 'conditions' => array('User.id' => $ids), - 'order' => 'User.id' - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ))); - $this->assertEquals($expected, $result); - - // These tests are expected to fail on SQL Server since the LIMIT/OFFSET - // hack can't handle small record counts. - if (!($this->db instanceof Sqlserver)) { - $result = $TestModel->find('all', array('limit' => 3, 'page' => 2)); - $expected = array( - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ))); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('all', array('limit' => 3, 'page' => 3)); - $expected = array(); - $this->assertEquals($expected, $result); - } - } - - /** - * test find('list') method - * - * @return void - */ - public function testGenerateFindList() { - $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment'); - - $TestModel = new Article(); - $TestModel->displayField = 'title'; - - $result = $TestModel->find('list', array( - 'order' => 'Article.title ASC' - )); - - $expected = array( - 1 => 'First Article', - 2 => 'Second Article', - 3 => 'Third Article' - ); - $this->assertEquals($expected, $result); - - $db = ConnectionManager::getDataSource('test'); - if ($db instanceof Mysql) { - $result = $TestModel->find('list', array( - 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') - )); - $expected = array( - 1 => 'First Article', - 3 => 'Third Article', - 2 => 'Second Article' - ); - $this->assertEquals($expected, $result); - } - - $result = Hash::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC', - 'fields' => array('id', 'title') - )), '{n}.Article.id', '{n}.Article.title' - ); - $expected = array( - 1 => 'First Article', - 2 => 'Second Article', - 3 => 'Third Article' - ); - $this->assertEquals($expected, $result); - - $result = Hash::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC' - )), '{n}.Article.id', '{n}.Article' - ); - $expected = array( - 1 => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 2 => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 3 => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - )); - - $this->assertEquals($expected, $result); - - $result = Hash::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC' - )), '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' - ); - $expected = array( - 1 => array( - 1 => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 3 => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - )), - 3 => array( - 2 => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))); - - $this->assertEquals($expected, $result); - - $result = Hash::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC', - 'fields' => array('id', 'title', 'user_id') - )), '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' - ); - - $expected = array( - 1 => array( - 1 => 'First Article', - 3 => 'Third Article' - ), - 3 => array( - 2 => 'Second Article' - )); - $this->assertEquals($expected, $result); - - $TestModel = new Apple(); - $expected = array( - 1 => 'Red Apple 1', - 2 => 'Bright Red Apple', - 3 => 'green blue', - 4 => 'Test Name', - 5 => 'Blue Green', - 6 => 'My new apple', - 7 => 'Some odd color' - ); - - $this->assertEquals($expected, $TestModel->find('list')); - $this->assertEquals($expected, $TestModel->Parent->find('list')); - - $TestModel = new Post(); - $result = $TestModel->find('list', array( - 'fields' => 'Post.title' - )); - $expected = array( - 1 => 'First Post', - 2 => 'Second Post', - 3 => 'Third Post' - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('list', array( - 'fields' => 'title' - )); - $expected = array( - 1 => 'First Post', - 2 => 'Second Post', - 3 => 'Third Post' - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('list', array( - 'fields' => array('title', 'id') - )); - $expected = array( - 'First Post' => '1', - 'Second Post' => '2', - 'Third Post' => '3' - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('list', array( - 'fields' => array('title', 'id', 'created') - )); - $expected = array( - '2007-03-18 10:39:23' => array( - 'First Post' => '1' - ), - '2007-03-18 10:41:23' => array( - 'Second Post' => '2' - ), - '2007-03-18 10:43:23' => array( - 'Third Post' => '3' - ), - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('list', array( - 'fields' => array('Post.body') - )); - $expected = array( - 1 => 'First Post Body', - 2 => 'Second Post Body', - 3 => 'Third Post Body' - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('list', array( - 'fields' => array('Post.title', 'Post.body') - )); - $expected = array( - 'First Post' => 'First Post Body', - 'Second Post' => 'Second Post Body', - 'Third Post' => 'Third Post Body' - ); - $this->assertEquals($expected, $result); - - $result = $TestModel->find('list', array( - 'fields' => array('Post.id', 'Post.title', 'Author.user'), - 'recursive' => 1 - )); - $expected = array( - 'mariano' => array( - 1 => 'First Post', - 3 => 'Third Post' - ), - 'larry' => array( - 2 => 'Second Post' - )); - $this->assertEquals($expected, $result); - - $TestModel = new User(); - $result = $TestModel->find('list', array( - 'fields' => array('User.user', 'User.password') - )); - $expected = array( - 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' - ); - $this->assertEquals($expected, $result); - - $TestModel = new ModifiedAuthor(); - $result = $TestModel->find('list', array( - 'fields' => array('Author.id', 'Author.user') - )); - $expected = array( - 1 => 'mariano (CakePHP)', - 2 => 'nate (CakePHP)', - 3 => 'larry (CakePHP)', - 4 => 'garrett (CakePHP)' - ); - $this->assertEquals($expected, $result); - - $TestModel = new Article(); - $TestModel->displayField = 'title'; - $result = $TestModel->find('list', array( - 'conditions' => array('User.user' => 'mariano'), - 'recursive' => 0 - )); - $expected = array( - 1 => 'First Article', - 3 => 'Third Article' - ); - $this->assertEquals($expected, $result); - } - - /** - * testFindField method - * - * @return void - */ - public function testFindField() { - $this->loadFixtures('User'); - $TestModel = new User(); - - $TestModel->id = 1; - $result = $TestModel->field('user'); - $this->assertEquals('mariano', $result); - - $result = $TestModel->field('User.user'); - $this->assertEquals('mariano', $result); - - $TestModel->id = false; - $result = $TestModel->field('user', array( - 'user' => 'mariano' - )); - $this->assertEquals('mariano', $result); - - $TestModel->order = null; - - $result = $TestModel->field('COUNT(*) AS count', true); - $this->assertEquals(4, $result); - - $result = $TestModel->field('COUNT(*)', true); - $this->assertEquals(4, $result); - } - - /** - * testFindUnique method - * - * @return void - */ - public function testFindUnique() { - $this->loadFixtures('User'); - $TestModel = new User(); - - $this->assertFalse($TestModel->isUnique(array( - 'user' => 'nate' - ))); - $TestModel->id = 2; - $this->assertTrue($TestModel->isUnique(array( - 'user' => 'nate' - ))); - $this->assertFalse($TestModel->isUnique(array( - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' - ))); - } - - /** - * test find('count') method - * - * @return void - */ - public function testFindCount() { - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag'); - - $TestModel = new User(); - $this->db->getLog(false, true); - $result = $TestModel->find('count'); - $this->assertEquals(4, $result); - - $this->db->getLog(false, true); - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->order = 'User.id'; - $result = $TestModel->find('count'); - $this->db->fullDebug = $fullDebug; - $this->assertEquals(4, $result); - - $log = $this->db->getLog(); - $this->assertTrue(isset($log['log'][0]['query'])); - $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']); - - $Article = new Article(); - $Article->order = null; - $Article->recursive = -1; - - $expected = count($Article->find('all', array( - 'fields' => array('Article.user_id'), - 'group' => 'Article.user_id') - )); - $result = $Article->find('count', array('group' => array('Article.user_id'))); - $this->assertEquals($expected, $result); - - $expected = count($Article->find('all', array( - 'fields' => array('Article.user_id'), - 'conditions' => array('Article.user_id' => 1), - 'group' => 'Article.user_id') - )); - $result = $Article->find('count', array( - 'conditions' => array('Article.user_id' => 1), - 'group' => array('Article.user_id'), - )); - $this->assertEquals($expected, $result); - } - - /** - * Test that find('first') does not use the id set to the object. - * - * @return void - */ - public function testFindFirstNoIdUsed() { - $this->loadFixtures('Project'); - - $Project = new Project(); - $Project->id = 3; - $result = $Project->find('first'); - - $this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved'); - } - - /** - * test find with COUNT(DISTINCT field) - * - * @return void - */ - public function testFindCountDistinct() { - $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.'); - $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.'); - - $this->loadFixtures('Project', 'Thread'); - $TestModel = new Project(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - - $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); - $this->assertEquals(4, $result); - } - - /** - * Test find(count) with Db::expression - * - * @return void - */ - public function testFindCountWithDbExpressions() { - $this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.'); - - $this->loadFixtures('Project', 'Thread'); - $db = ConnectionManager::getDataSource('test'); - $TestModel = new Project(); - - $result = $TestModel->find('count', array('conditions' => array( - $db->expression('Project.name = \'Project 3\'') - ))); - $this->assertEquals(1, $result); - - $result = $TestModel->find('count', array('conditions' => array( - 'Project.name' => $db->expression('\'Project 3\'') - ))); - $this->assertEquals(1, $result); - } - - /** - * testFindMagic method - * - * @return void - */ - public function testFindMagic() { - $this->loadFixtures('User'); - $TestModel = new User(); - - $result = $TestModel->findByUser('mariano'); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )); - $this->assertEquals($expected, $result); - - $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); - $expected = array('User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )); - $this->assertEquals($expected, $result); - } - - /** - * testRead method - * - * @return void - */ - public function testRead() { - $this->loadFixtures('User', 'Article'); - $TestModel = new User(); - - $result = $TestModel->read(); - $this->assertFalse($result); - - $TestModel->id = 2; - $result = $TestModel->read(); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )); - $this->assertEquals($expected, $result); - - $result = $TestModel->read(null, 2); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )); - $this->assertEquals($expected, $result); - - $TestModel->id = 2; - $result = $TestModel->read(array('id', 'user')); - $expected = array('User' => array('id' => '2', 'user' => 'nate')); - $this->assertEquals($expected, $result); - - $result = $TestModel->read('id, user', 2); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - )); - $this->assertEquals($expected, $result); - - $result = $TestModel->bindModel(array('hasMany' => array('Article'))); - $this->assertTrue($result); - - $TestModel->id = 1; - $result = $TestModel->read('id, user'); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Article' => array( - array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); - $this->assertEquals($expected, $result); - } - - /** - * testRecursiveRead method - * - * @return void - */ - public function testRecursiveRead() { - $this->loadFixtures( - 'User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Featured', 'ArticleFeatured' - ); - $TestModel = new User(); - - $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); - $this->assertTrue($result); - - $TestModel->recursive = 0; - $result = $TestModel->read('id, user', 1); - $expected = array( - 'User' => array('id' => '1', 'user' => 'mariano'), - ); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 1; - $result = $TestModel->read('id, user', 1); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Article' => array( - array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); - $this->assertEquals($expected, $result); - - $TestModel->recursive = 2; - $result = $TestModel->read('id, user', 3); - $expected = array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Article' => array( - array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31', - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( + $expected = array( array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1.1%') + )); + $expected = array( + array('Category' => + array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 2) + )); + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ) ), array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2' + ), + 'children' => array() ), array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))))); - $this->assertEquals($expected, $result); - } + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEquals($expected, $result); - public function testRecursiveFindAll() { - $this->loadFixtures( - 'User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'ArticleFeaturedsTags', 'Featured', 'Category' - ); - $TestModel = new Article(); + $result = $TestModel->find('all', array( + 'fields' => 'id, name, parent_id', + 'conditions' => array('Category.id !=' => 1) + )); + $expected = array( + array('Category' => array( + 'id' => '2', + 'name' => 'Category 1.1', + 'parent_id' => '1' + )), + array('Category' => array( + 'id' => '3', + 'name' => 'Category 1.2', + 'parent_id' => '1' + )), + array('Category' => array( + 'id' => '4', + 'name' => 'Category 2', + 'parent_id' => '0' + )), + array('Category' => array( + 'id' => '5', + 'name' => 'Category 3', + 'parent_id' => '0' + )), + array('Category' => array( + 'id' => '6', + 'name' => 'Category 3.1', + 'parent_id' => '5' + )), + array('Category' => array( + 'id' => '7', + 'name' => 'Category 1.1.1', + 'parent_id' => '2' + )), + array('Category' => array( + 'id' => '8', + 'name' => 'Category 1.1.2', + 'parent_id' => '2' + ))); + $this->assertEquals($expected, $result); - $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 1) + )); + $expected = array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ); + $this->assertEquals($expected, $result); + } + +/** + * test find('neighbors') + * + * @return void + */ + public function testFindNeighbors() { + $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); + $TestModel = new Article(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('fields' => array('id'))); + + $this->assertNull($result['prev']); + $this->assertEquals(array('id' => 2), $result['next']['Article']); + $this->assertEquals(2, count($result['next']['Comment'])); + $this->assertEquals(2, count($result['next']['Tag'])); + + $TestModel->id = 2; + $TestModel->recursive = 0; + $result = $TestModel->find('neighbors', array( + 'fields' => array('id') + )); + + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1 + )), + 'next' => array( + 'Article' => array( + 'id' => 3 + ))); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $TestModel->recursive = 1; + $result = $TestModel->find('neighbors', array('fields' => array('id'))); + + $this->assertNull($result['next']); + $this->assertEquals(array('id' => 2), $result['prev']['Article']); + $this->assertEquals(2, count($result['prev']['Comment'])); + $this->assertEquals(2, count($result['prev']['Tag'])); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => null, + 'next' => array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ) + ); + $this->assertEquals($expected, $result); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + 'next' => array( + 'Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ) + ) + ); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ), + 'next' => null + ); + $this->assertEquals($expected, $result); + + $TestModel->recursive = 0; + $TestModel->id = 1; + $one = $TestModel->read(); + $TestModel->id = 2; + $two = $TestModel->read(); + $TestModel->id = 3; + $three = $TestModel->read(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => null, 'next' => $two); + $this->assertEquals($expected, $result); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => $one, 'next' => $three); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => $two, 'next' => null); + $this->assertEquals($expected, $result); + + $TestModel->recursive = 2; + $TestModel->id = 1; + $one = $TestModel->read(); + $TestModel->id = 2; + $two = $TestModel->read(); + $TestModel->id = 3; + $three = $TestModel->read(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => null, 'next' => $two); + $this->assertEquals($expected, $result); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => $one, 'next' => $three); + $this->assertEquals($expected, $result); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => $two, 'next' => null); + $this->assertEquals($expected, $result); + } + +/** + * Test find(neighbors) with missing fields so no neighbors are found. + * + * @return void + */ + public function testFindNeighborsNoPrev() { + $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); + $Article = new Article(); + + $result = $Article->find('neighbors', array( + 'field' => 'Article.title', + 'value' => 'Second Article', + 'fields' => array('id'), + 'conditions' => array( + 'Article.title LIKE' => '%Article%' + ), + 'recursive' => 0, + )); + $expected = array( + 'prev' => null, + 'next' => null + ); + $this->assertEquals($expected, $result); + } + +/** + * testFindCombinedRelations method + * + * @return void + */ + public function testFindCombinedRelations() { + $this->skipIf($this->db instanceof Sqlserver, 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.'); + + $this->loadFixtures('Apple', 'Sample'); + $TestModel = new Apple(); + + $result = $TestModel->find('all'); + + $expected = array( + array( + 'Apple' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '2', + 'apple_id' => '2', + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '1', + 'apple_id' => '3', + 'name' => 'sample1' + ), + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '3', + 'apple_id' => '4', + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '4', + 'apple_id' => '5', + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array() + )); + $this->assertEquals($expected, $result); + } + +/** + * testSaveEmpty method + * + * @return void + */ + public function testSaveEmpty() { + $this->loadFixtures('Thread'); + $TestModel = new Thread(); + $data = array(); + $expected = $TestModel->save($data); + $this->assertFalse($expected); + } + +/** + * testFindAllWithConditionInChildQuery + * + * @return void + */ + public function testFindAllWithConditionInChildQuery() { + $this->loadFixtures('Basket', 'FilmFile'); + + $TestModel = new Basket(); + $recursive = 3; + $result = $TestModel->find('all', compact('recursive')); + + $expected = array( + array( + 'Basket' => array( + 'id' => 1, + 'type' => 'nonfile', + 'name' => 'basket1', + 'object_id' => 1, + 'user_id' => 1, + ), + 'FilmFile' => array( + 'id' => '', + 'name' => '', + ) + ), + array( + 'Basket' => array( + 'id' => 2, + 'type' => 'file', + 'name' => 'basket2', + 'object_id' => 2, + 'user_id' => 1, + ), + 'FilmFile' => array( + 'id' => 2, + 'name' => 'two', + ) + ), + ); + $this->assertEquals($expected, $result); + } + +/** + * testFindAllWithConditionsHavingMixedDataTypes method + * + * @return void + */ + public function testFindAllWithConditionsHavingMixedDataTypes() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag'); + $TestModel = new Article(); + $expected = array( + array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ) + ); + $conditions = array('id' => array('1', 2)); + $recursive = -1; + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); + $this->assertEquals($expected, $result); + + $this->skipIf($this->db instanceof Postgres, 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.'); + + $conditions = array('id' => array('1', 2, '3.0')); + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); + $expected = array( + array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ), + array( + 'Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ) + ) + ); + $this->assertEquals($expected, $result); + } + +/** + * testBindUnbind method + * + * @return void + */ + public function testBindUnbind() { + $this->loadFixtures( + 'User', + 'Comment', + 'FeatureSet', + 'DeviceType', + 'DeviceTypeCategory', + 'ExteriorTypeCategory', + 'Device', + 'Document', + 'DocumentDirectory' + ); + $TestModel = new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + + $this->assertEquals($expected, $result); + + $TestModel->resetAssociations(); + $result = $TestModel->hasMany; + $this->assertSame(array(), $result); + + $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + + $this->assertEquals($expected, $result); + + $result = $TestModel->hasMany; + $expected = array( + 'Comment' => array( + 'className' => 'Comment', + 'foreignKey' => 'user_id', + 'conditions' => null, + 'fields' => null, + 'order' => null, + 'limit' => null, + 'offset' => null, + 'dependent' => null, + 'exclusive' => null, + 'finderQuery' => null, + 'counterQuery' => null + )); + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $this->assertTrue($result); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => + 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEquals($expected, $result); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array('hasMany' => array( + 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + + $this->assertEquals($expected, $result); + + $TestModel2 = new DeviceType(); + + $expected = array( + 'className' => 'FeatureSet', + 'foreignKey' => 'feature_set_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'counterCache' => '' + ); + $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); + + $TestModel2->bindModel(array( + 'belongsTo' => array( + 'FeatureSet' => array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true) + ) + ) + )); + $expected['conditions'] = array('active' => true); + $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); + + $TestModel2->bindModel(array( + 'belongsTo' => array( + 'FeatureSet' => array( + 'className' => 'FeatureSet', + 'foreignKey' => false, + 'conditions' => array('Feature.name' => 'DeviceType.name') + ) + ) + )); + $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); + $expected['foreignKey'] = false; + $this->assertEquals($expected, $TestModel2->belongsTo['FeatureSet']); + + $TestModel2->bindModel(array( + 'hasMany' => array( + 'NewFeatureSet' => array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true) + ) + ) + )); + + $expected = array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true), + 'foreignKey' => 'device_type_id', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'dependent' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ); + $this->assertEquals($expected, $TestModel2->hasMany['NewFeatureSet']); + $this->assertTrue(is_object($TestModel2->NewFeatureSet)); + } + +/** + * testBindMultipleTimes method + * + * @return void + */ + public function testBindMultipleTimes() { + $this->loadFixtures('User', 'Comment', 'Article', 'Tag', 'ArticlesTag'); + $TestModel = new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Comment') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Items' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Article') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array( + array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Items' => array() + )); + + $this->assertEquals($expected, $result); + } + +/** + * test that multiple reset = true calls to bindModel() result in the original associations. + * + * @return void + */ + public function testBindModelMultipleTimesResetCorrectly() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new User(); + + $TestModel->bindModel(array('hasMany' => array('Comment'))); + $TestModel->bindModel(array('hasMany' => array('Comment'))); + $TestModel->resetAssociations(); + + $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind'); + } + +/** + * testBindMultipleTimes method with different reset settings + * + * @return void + */ + public function testBindMultipleTimesWithDifferentResetSettings() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->bindModel(array( + 'hasMany' => array('Comment') + )); + $this->assertTrue($result); + $result = $TestModel->bindModel( + array('hasMany' => array('Article')), + false + ); + $this->assertTrue($result); + + $result = array_keys($TestModel->hasMany); + $expected = array('Comment', 'Article'); + $this->assertEquals($expected, $result); + + $TestModel->resetAssociations(); + + $result = array_keys($TestModel->hasMany); + $expected = array('Article'); + $this->assertEquals($expected, $result); + } + +/** + * test that bindModel behaves with Custom primary Key associations + * + * @return void + */ + public function testBindWithCustomPrimaryKey() { + $this->loadFixtures('Story', 'StoriesTag', 'Tag'); + $Model = ClassRegistry::init('StoriesTag'); + $Model->bindModel(array( + 'belongsTo' => array( + 'Tag' => array( + 'className' => 'Tag', + 'foreignKey' => 'story' + )))); + + $result = $Model->find('all'); + $this->assertFalse(empty($result)); + } + +/** + * test that calling unbindModel() with reset == true multiple times + * leaves associations in the correct state. + * + * @return void + */ + public function testUnbindMultipleTimesResetCorrectly() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new Article10(); + + $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $TestModel->resetAssociations(); + + $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed'); + } + +/** + * testBindMultipleTimes method with different reset settings + * + * @return void + */ + public function testUnBindMultipleTimesWithDifferentResetSettings() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel = new Comment(); + + $result = array_keys($TestModel->belongsTo); + $expected = array('Article', 'User'); + $this->assertEquals($expected, $result); + + $result = $TestModel->unbindModel(array( + 'belongsTo' => array('User') + )); + $this->assertTrue($result); + $result = $TestModel->unbindModel( + array('belongsTo' => array('Article')), + false + ); + $this->assertTrue($result); + + $result = array_keys($TestModel->belongsTo); + $expected = array(); + $this->assertEquals($expected, $result); + + $TestModel->resetAssociations(); + + $result = array_keys($TestModel->belongsTo); + $expected = array('User'); + $this->assertEquals($expected, $result); + } + +/** + * testAssociationAfterFind method + * + * @return void + */ + public function testAssociationAfterFind() { + $this->loadFixtures('Post', 'Author', 'Comment'); + $TestModel = new Post(); + $result = $TestModel->find('all', array( + 'order' => array('Post.id' => 'ASC') + )); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ))); + $this->assertEquals($expected, $result); + unset($TestModel); + + $Author = new Author(); + $Author->Post->bindModel(array( + 'hasMany' => array( + 'Comment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ))); + $result = $Author->find('all', array( + 'conditions' => array('Author.id' => 1), + 'order' => array('Author.id' => 'ASC'), + 'recursive' => 2 + )); + $expected = array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31', + 'callback' => 'Fire' + ); + $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); + } + +/** + * testDeeperAssociationAfterFind method + * + * @return void + */ + public function testDeeperAssociationAfterFind() { + $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article'); + + $Post = new Post(); + $Post->bindModel(array( + 'hasMany' => array( + 'Comment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ))); + $Post->Comment->bindModel(array( + 'hasOne' => array( + 'Attachment' => array( + 'className' => 'ModifiedAttachment', + ) + ))); + + $result = $Post->find('first', array( + 'conditions' => array('Post.id' => 2), + 'recursive' => 2 + )); + $this->assertTrue(isset($result['Comment'][0]['callback'])); + $this->assertEquals('Fire', $result['Comment'][0]['callback']); + $this->assertTrue(isset($result['Comment'][0]['Attachment']['callback'])); + $this->assertEquals('Fired', $result['Comment'][0]['Attachment']['callback']); + } + +/** + * Tests that callbacks can be properly disabled + * + * @return void + */ + public function testCallbackDisabling() { + $this->loadFixtures('Author'); + $TestModel = new ModifiedAuthor(); + + $result = Hash::extract($TestModel->find('all'), '{n}.Author.user'); + $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); + $this->assertEquals($expected, $result); + + $result = Hash::extract($TestModel->find('all', array('callbacks' => 'after')), '{n}.Author.user'); + $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); + $this->assertEquals($expected, $result); + + $result = Hash::extract($TestModel->find('all', array('callbacks' => 'before')), '{n}.Author.user'); + $expected = array('mariano', 'nate', 'larry', 'garrett'); + $this->assertEquals($expected, $result); + + $result = Hash::extract($TestModel->find('all', array('callbacks' => false)), '{n}.Author.user'); + $expected = array('mariano', 'nate', 'larry', 'garrett'); + $this->assertEquals($expected, $result); + } + +/** + * testAssociationAfterFindCallbacksDisabled method + * + * @return void + */ + public function testAssociationAfterFindCalbacksDisabled() { + $this->loadFixtures('Post', 'Author', 'Comment'); + $TestModel = new Post(); + $result = $TestModel->find('all', array( + 'callbacks' => false, + 'order' => array('Post.id' => 'ASC'), + )); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ))); + $this->assertEquals($expected, $result); + unset($TestModel); + + $Author = new Author(); + $Author->Post->bindModel(array( + 'hasMany' => array( + 'Comment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ))); + $result = $Author->find('all', array( + 'conditions' => array('Author.id' => 1), + 'recursive' => 2, + 'order' => array('Author.id' => 'ASC'), + 'callbacks' => false + )); + $expected = array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array(), - 'Tag' => array() - ) - ); - $this->assertEquals($expected, $result); + ); + $this->assertEquals($expected, $result[0]['Post'][0]['Comment'][0]); + } - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 3), - 'limit' => 1, - 'recursive' => 2 - )); +/** + * Tests that the database configuration assigned to the model can be changed using + * (before|after)Find callbacks + * + * @return void + */ + public function testCallbackSourceChange() { + $this->loadFixtures('Post'); + $TestModel = new Post(); + $this->assertEquals(3, count($TestModel->find('all'))); + } - $expected = array( - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' +/** + * testCallbackSourceChangeUnknownDatasource method + * + * @expectedException MissingDatasourceConfigException + * @return void + */ + public function testCallbackSourceChangeUnknownDatasource() { + $this->loadFixtures('Post', 'Author'); + $TestModel = new Post(); + $this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); + } + +/** + * testMultipleBelongsToWithSameClass method + * + * @return void + */ + public function testMultipleBelongsToWithSameClass() { + $this->loadFixtures( + 'DeviceType', + 'DeviceTypeCategory', + 'FeatureSet', + 'ExteriorTypeCategory', + 'Document', + 'Device', + 'DocumentDirectory' + ); + + $DeviceType = new DeviceType(); + + $DeviceType->recursive = 2; + $result = $DeviceType->read(null, 1); + + $expected = array( + 'DeviceType' => array( + 'id' => 1, + 'device_type_category_id' => 1, + 'feature_set_id' => 1, + 'exterior_type_category_id' => 1, + 'image_id' => 1, + 'extra1_id' => 1, + 'extra2_id' => 1, + 'name' => 'DeviceType 1', + 'order' => 0 ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' + 'Image' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'Extra1' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'Extra2' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'DeviceTypeCategory' => array( + 'id' => 1, + 'name' => 'DeviceTypeCategory 1' ), - 'Attachment' => array( - 'id' => '1', - 'comment_id' => 5, - 'attachment' => 'attachment.zip', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' + 'FeatureSet' => array( + 'id' => 1, + 'name' => 'FeatureSet 1' ), - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' + 'ExteriorTypeCategory' => array( + 'id' => 1, + 'image_id' => 1, + 'name' => 'ExteriorTypeCategory 1', + 'Image' => array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + )), + 'Device' => array( + array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + ), + array( + 'id' => 2, + 'device_type_id' => 1, + 'name' => 'Device 2', + 'typ' => 1 + ), + array( + 'id' => 3, + 'device_type_id' => 1, + 'name' => 'Device 3', + 'typ' => 2 + ))); + + $this->assertEquals($expected, $result); + } + +/** + * testHabtmRecursiveBelongsTo method + * + * @return void + */ + public function testHabtmRecursiveBelongsTo() { + $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); + $Portfolio = new Portfolio(); + + $result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3)); + $expected = array( + 'Portfolio' => array( + 'id' => 2, + 'seller_id' => 1, + 'name' => 'Portfolio 2' ), - 'Attachment' => array() - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' + 'Item' => array( + array( + 'id' => 2, + 'syfile_id' => 2, + 'published' => false, + 'name' => 'Item 2', + 'ItemsPortfolio' => array( + 'id' => 2, + 'item_id' => 2, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 2, + 'image_id' => 2, + 'name' => 'Syfile 2', + 'item_count' => null, + 'Image' => array( + 'id' => 2, + 'name' => 'Image 2' + ) + )), + array( + 'id' => 6, + 'syfile_id' => 6, + 'published' => false, + 'name' => 'Item 6', + 'ItemsPortfolio' => array( + 'id' => 6, + 'item_id' => 6, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 6, + 'image_id' => null, + 'name' => 'Syfile 6', + 'item_count' => null, + 'Image' => array() )))); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result); + } - $Featured = new Featured(); +/** + * testNonNumericHabtmJoinKey method + * + * @return void + */ + public function testNonNumericHabtmJoinKey() { + $this->loadFixtures('Post', 'Tag', 'PostsTag', 'Author'); + $Post = new Post(); + $Post->bindModel(array( + 'hasAndBelongsToMany' => array('Tag') + )); + $Post->Tag->primaryKey = 'tag'; - $Featured->recursive = 2; - $Featured->bindModel(array( - 'belongsTo' => array( - 'ArticleFeatured' => array( - 'conditions' => "ArticleFeatured.published = 'Y'", - 'fields' => 'id, title, user_id, published' - ) - ) - )); + $result = $Post->find('all', array( + 'order' => 'Post.id ASC', + )); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => 3, + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31', + 'test' => 'working' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ), + 'Tag' => array() + )); + $this->assertEquals($expected, $result); + } - $Featured->ArticleFeatured->unbindModel(array( - 'hasMany' => array('Attachment', 'Comment'), - 'hasAndBelongsToMany' => array('Tag')) - ); +/** + * testHabtmFinderQuery method + * + * @return void + */ + public function testHabtmFinderQuery() { + $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); + $Article = new Article(); - $orderBy = 'ArticleFeatured.id ASC'; - $result = $Featured->find('all', array( - 'order' => $orderBy, 'limit' => 3 + $sql = $this->db->buildStatement( + array( + 'fields' => $this->db->fields($Article->Tag, null, array( + 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id' + )), + 'table' => $this->db->fullTableName('tags'), + 'alias' => 'Tag', + 'limit' => null, + 'offset' => null, + 'group' => null, + 'joins' => array(array( + 'alias' => 'ArticlesTag', + 'table' => 'articles_tags', + 'conditions' => array( + array("ArticlesTag.article_id" => '{$__cakeID__$}'), + array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) + ) + )), + 'conditions' => array(), + 'order' => null + ), + $Article + ); + + $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; + $result = $Article->find('first'); + $expected = array( + array( + 'id' => '1', + 'tag' => 'tag1' + ), + array( + 'id' => '2', + 'tag' => 'tag2' )); - $expected = array( - array( - 'Featured' => array( - 'id' => '1', - 'article_featured_id' => '1', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'ArticleFeatured' => array( - 'id' => '1', - 'title' => 'First Article', - 'user_id' => '1', - 'published' => 'Y', - 'User' => array( + $this->assertEquals($expected, $result['Tag']); + } + +/** + * testHabtmLimitOptimization method + * + * @return void + */ + public function testHabtmLimitOptimization() { + $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); + $TestModel = new Article(); + + $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; + $result = $TestModel->read(null, 2); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + + $this->assertEquals($expected, $result); + + $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1; + $result = $TestModel->read(null, 2); + unset($expected['Tag'][1]); + + $this->assertEquals($expected, $result); + } + +/** + * testHasManyLimitOptimization method + * + * @return void + */ + public function testHasManyLimitOptimization() { + $this->loadFixtures('Project', 'Thread', 'Message', 'Bid'); + $Project = new Project(); + $Project->recursive = 3; + + $result = $Project->find('all', array( + 'order' => 'Project.id ASC', + )); + $expected = array( + array( + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1', + 'Bid' => array( + 'id' => 1, + 'message_id' => 1, + 'name' => 'Bid 1.1' + )))), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 2, + 'thread_id' => 2, + 'name' => 'Thread 2, Message 1', + 'Bid' => array( + 'id' => 4, + 'message_id' => 2, + 'name' => 'Bid 2.1' + )))))), + array( + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1', + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2', + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ))), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1', + 'Bid' => array( + 'id' => 3, + 'message_id' => 3, + 'name' => 'Bid 3.1' + )))))), + array( + 'Project' => array( + 'id' => 3, + 'name' => 'Project 3' + ), + 'Thread' => array() + )); + + $this->assertEquals($expected, $result); + } + +/** + * testFindAllRecursiveSelfJoin method + * + * @return void + */ + public function testFindAllRecursiveSelfJoin() { + $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement'); + $TestModel = new Home(); + $TestModel->recursive = 2; + + $result = $TestModel->find('all', array( + 'order' => 'Home.id ASC', + )); + $expected = array( + array( + 'Home' => array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'AnotherArticle' => array( + 'id' => '1', + 'title' => 'First Article', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )))), + array( + 'Home' => array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'AnotherArticle' => array( + 'id' => '3', + 'title' => 'Third Article', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'Home' => array( + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))))); + + $this->assertEquals($expected, $result); + } + +/** + * testFindAllRecursiveWithHabtm method + * + * @return void + */ + public function testFindAllRecursiveWithHabtm() { + $this->loadFixtures( + 'MyCategoriesMyUsers', + 'MyCategoriesMyProducts', + 'MyCategory', + 'MyUser', + 'MyProduct' + ); + + $MyUser = new MyUser(); + $MyUser->recursive = 2; + + $result = $MyUser->find('all', array( + 'order' => 'MyUser.id ASC' + )); + $expected = array( + array( + 'MyUser' => array('id' => '1', 'firstname' => 'userA'), + 'MyCategory' => array( + array( + 'id' => '1', + 'name' => 'A', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ))), + array( + 'id' => '3', + 'name' => 'C', + 'MyProduct' => array( + array( + 'id' => '2', + 'name' => 'computer' + ))))), + array( + 'MyUser' => array( + 'id' => '2', + 'firstname' => 'userB' + ), + 'MyCategory' => array( + array( + 'id' => '1', + 'name' => 'A', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ))), + array( + 'id' => '2', + 'name' => 'B', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ), + array( + 'id' => '2', + 'name' => 'computer' + )))))); + + $this->assertEquals($expected, $result); + } + +/** + * testReadFakeThread method + * + * @return void + */ + public function testReadFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel = new CategoryThread(); + + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $TestModel->id = 7; + $result = $TestModel->read(); + $expected = array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); + + $this->db->fullDebug = $fullDebug; + $this->assertEquals($expected, $result); + } + +/** + * testFindFakeThread method + * + * @return void + */ + public function testFindFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel = new CategoryThread(); + + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7))); + + $expected = array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); + + $this->db->fullDebug = $fullDebug; + $this->assertEquals($expected, $result); + } + +/** + * testFindAllFakeThread method + * + * @return void + */ + public function testFindAllFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel = new CategoryThread(); + + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $result = $TestModel->find('all'); + $expected = array( + array( + 'CategoryThread' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => null, + 'parent_id' => null, + 'name' => null, + 'created' => null, + 'updated' => null, + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))), + array( + 'CategoryThread' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))), + array( + 'CategoryThread' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))))), + array( + 'CategoryThread' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))))), + array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + )))))))); + + $this->db->fullDebug = $fullDebug; + $this->assertEquals($expected, $result); + } + +/** + * testConditionalNumerics method + * + * @return void + */ + public function testConditionalNumerics() { + $this->loadFixtures('NumericArticle'); + $NumericArticle = new NumericArticle(); + $data = array('conditions' => array('title' => '12345abcde')); + $result = $NumericArticle->find('first', $data); + $this->assertTrue(!empty($result)); + + $data = array('conditions' => array('title' => '12345')); + $result = $NumericArticle->find('first', $data); + $this->assertTrue(empty($result)); + } + +/** + * test buildQuery() + * + * @return void + */ + public function testBuildQuery() { + $this->loadFixtures('User'); + $TestModel = new User(); + $TestModel->cacheQueries = false; + + $expected = array( + 'conditions' => array( + 'user' => 'larry' + ), + 'fields' => null, + 'joins' => array(), + 'limit' => null, + 'offset' => null, + 'order' => array( + 0 => null + ), + 'page' => 1, + 'group' => null, + 'callbacks' => true, + 'returnQuery' => true + ); + $result = $TestModel->buildQuery('all', array('returnQuery' => true, 'conditions' => array('user' => 'larry'))); + $this->assertEquals($expected, $result); + } + +/** + * test find('all') method + * + * @return void + */ + public function testFindAll() { + $this->loadFixtures('User'); + $TestModel = new User(); + $TestModel->cacheQueries = false; + + $result = $TestModel->find('all'); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array('conditions' => 'User.id > 2')); + $expected = array( + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%') + )); + $expected = array( + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array('conditions' => array('User.id' => '0'))); + $expected = array(); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array( + 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%') + ))); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC')); + $expected = array( + array('User' => array('user' => 'garrett')), + array('User' => array('user' => 'larry')), + array('User' => array('user' => 'mariano')), + array('User' => array('user' => 'nate'))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC')); + $expected = array( + array('User' => array('user' => 'nate')), + array('User' => array('user' => 'mariano')), + array('User' => array('user' => 'larry')), + array('User' => array('user' => 'garrett'))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array('limit' => 3, 'page' => 1)); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ))); + $this->assertEquals($expected, $result); + + $ids = array(4 => 1, 5 => 3); + $result = $TestModel->find('all', array( + 'conditions' => array('User.id' => $ids), + 'order' => 'User.id' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ))); + $this->assertEquals($expected, $result); + + // These tests are expected to fail on SQL Server since the LIMIT/OFFSET + // hack can't handle small record counts. + if (!($this->db instanceof Sqlserver)) { + $result = $TestModel->find('all', array('limit' => 3, 'page' => 2)); + $expected = array( + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('all', array('limit' => 3, 'page' => 3)); + $expected = array(); + $this->assertEquals($expected, $result); + } + } + +/** + * test find('list') method + * + * @return void + */ + public function testGenerateFindList() { + $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment'); + + $TestModel = new Article(); + $TestModel->displayField = 'title'; + + $result = $TestModel->find('list', array( + 'order' => 'Article.title ASC' + )); + + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); + $this->assertEquals($expected, $result); + + $db = ConnectionManager::getDataSource('test'); + if ($db instanceof Mysql) { + $result = $TestModel->find('list', array( + 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') + )); + $expected = array( + 1 => 'First Article', + 3 => 'Third Article', + 2 => 'Second Article' + ); + $this->assertEquals($expected, $result); + } + + $result = Hash::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title') + )), + '{n}.Article.id', '{n}.Article.title' + ); + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); + $this->assertEquals($expected, $result); + + $result = Hash::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC' + )), + '{n}.Article.id', '{n}.Article' + ); + $expected = array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )); + + $this->assertEquals($expected, $result); + + $result = Hash::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC' + )), + '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' + ); + $expected = array( + 1 => array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )), + 3 => array( + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))); + + $this->assertEquals($expected, $result); + + $result = Hash::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title', 'user_id') + )), + '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' + ); + + $expected = array( + 1 => array( + 1 => 'First Article', + 3 => 'Third Article' + ), + 3 => array( + 2 => 'Second Article' + )); + $this->assertEquals($expected, $result); + + $TestModel = new Apple(); + $expected = array( + 1 => 'Red Apple 1', + 2 => 'Bright Red Apple', + 3 => 'green blue', + 4 => 'Test Name', + 5 => 'Blue Green', + 6 => 'My new apple', + 7 => 'Some odd color' + ); + + $this->assertEquals($expected, $TestModel->find('list')); + $this->assertEquals($expected, $TestModel->Parent->find('list')); + + $TestModel = new Post(); + $result = $TestModel->find('list', array( + 'fields' => 'Post.title' + )); + $expected = array( + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('list', array( + 'fields' => 'title' + )); + $expected = array( + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id') + )); + $expected = array( + 'First Post' => '1', + 'Second Post' => '2', + 'Third Post' => '3' + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id', 'created') + )); + $expected = array( + '2007-03-18 10:39:23' => array( + 'First Post' => '1' + ), + '2007-03-18 10:41:23' => array( + 'Second Post' => '2' + ), + '2007-03-18 10:43:23' => array( + 'Third Post' => '3' + ), + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.body') + )); + $expected = array( + 1 => 'First Post Body', + 2 => 'Second Post Body', + 3 => 'Third Post Body' + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.title', 'Post.body') + )); + $expected = array( + 'First Post' => 'First Post Body', + 'Second Post' => 'Second Post Body', + 'Third Post' => 'Third Post Body' + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.id', 'Post.title', 'Author.user'), + 'recursive' => 1 + )); + $expected = array( + 'mariano' => array( + 1 => 'First Post', + 3 => 'Third Post' + ), + 'larry' => array( + 2 => 'Second Post' + )); + $this->assertEquals($expected, $result); + + $TestModel = new User(); + $result = $TestModel->find('list', array( + 'fields' => array('User.user', 'User.password') + )); + $expected = array( + 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' + ); + $this->assertEquals($expected, $result); + + $TestModel = new ModifiedAuthor(); + $result = $TestModel->find('list', array( + 'fields' => array('Author.id', 'Author.user') + )); + $expected = array( + 1 => 'mariano (CakePHP)', + 2 => 'nate (CakePHP)', + 3 => 'larry (CakePHP)', + 4 => 'garrett (CakePHP)' + ); + $this->assertEquals($expected, $result); + + $TestModel = new Article(); + $TestModel->displayField = 'title'; + $result = $TestModel->find('list', array( + 'conditions' => array('User.user' => 'mariano'), + 'recursive' => 0 + )); + $expected = array( + 1 => 'First Article', + 3 => 'Third Article' + ); + $this->assertEquals($expected, $result); + } + +/** + * testFindField method + * + * @return void + */ + public function testFindField() { + $this->loadFixtures('User'); + $TestModel = new User(); + + $TestModel->id = 1; + $result = $TestModel->field('user'); + $this->assertEquals('mariano', $result); + + $result = $TestModel->field('User.user'); + $this->assertEquals('mariano', $result); + + $TestModel->id = false; + $result = $TestModel->field('user', array( + 'user' => 'mariano' + )); + $this->assertEquals('mariano', $result); + + $result = $TestModel->field('COUNT(*) AS count', true); + $this->assertEquals(4, $result); + + $result = $TestModel->field('COUNT(*)', true); + $this->assertEquals(4, $result); + } + +/** + * testFindUnique method + * + * @return void + */ + public function testFindUnique() { + $this->loadFixtures('User'); + $TestModel = new User(); + + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate' + ))); + $TestModel->id = 2; + $this->assertTrue($TestModel->isUnique(array( + 'user' => 'nate' + ))); + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' + ))); + } + +/** + * test find('count') method + * + * @return void + */ + public function testFindCount() { + $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag'); + + $TestModel = new User(); + $this->db->getLog(false, true); + $result = $TestModel->find('count'); + $this->assertEquals(4, $result); + + $this->db->getLog(false, true); + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->order = 'User.id'; + $result = $TestModel->find('count'); + $this->db->fullDebug = $fullDebug; + $this->assertEquals(4, $result); + + $log = $this->db->getLog(); + $this->assertTrue(isset($log['log'][0]['query'])); + $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']); + + $Article = new Article(); + $Article->recursive = -1; + $expected = count($Article->find('all', array( + 'fields' => array('Article.user_id'), + 'group' => 'Article.user_id') + )); + $result = $Article->find('count', array('group' => array('Article.user_id'))); + $this->assertEquals($expected, $result); + + $expected = count($Article->find('all', array( + 'fields' => array('Article.user_id'), + 'conditions' => array('Article.user_id' => 1), + 'group' => 'Article.user_id') + )); + $result = $Article->find('count', array( + 'conditions' => array('Article.user_id' => 1), + 'group' => array('Article.user_id'), + )); + $this->assertEquals($expected, $result); + } + +/** + * Test that find('first') does not use the id set to the object. + * + * @return void + */ + public function testFindFirstNoIdUsed() { + $this->loadFixtures('Project'); + + $Project = new Project(); + $Project->id = 3; + $result = $Project->find('first'); + + $this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved'); + } + +/** + * test find with COUNT(DISTINCT field) + * + * @return void + */ + public function testFindCountDistinct() { + $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.'); + $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.'); + + $this->loadFixtures('Project', 'Thread'); + $TestModel = new Project(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + + $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); + $this->assertEquals(4, $result); + } + +/** + * Test find(count) with Db::expression + * + * @return void + */ + public function testFindCountWithDbExpressions() { + $this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.'); + + $this->loadFixtures('Project', 'Thread'); + $db = ConnectionManager::getDataSource('test'); + $TestModel = new Project(); + + $result = $TestModel->find('count', array('conditions' => array( + $db->expression('Project.name = \'Project 3\'') + ))); + $this->assertEquals(1, $result); + + $result = $TestModel->find('count', array('conditions' => array( + 'Project.name' => $db->expression('\'Project 3\'') + ))); + $this->assertEquals(1, $result); + } + +/** + * testFindMagic method + * + * @return void + */ + public function testFindMagic() { + $this->loadFixtures('User'); + $TestModel = new User(); + + $result = $TestModel->findByUser('mariano'); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )); + $this->assertEquals($expected, $result); + + $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); + $expected = array('User' => array( 'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' - ), - 'Category' => array(), - 'Featured' => array( - 'id' => '1', - 'article_featured_id' => '1', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - )), - array( - 'Featured' => array( - 'id' => '2', - 'article_featured_id' => '2', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'ArticleFeatured' => array( - 'id' => '2', - 'title' => 'Second Article', - 'user_id' => '3', - 'published' => 'Y', - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Category' => array(), - 'Featured' => array( - 'id' => '2', - 'article_featured_id' => '2', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))); - $this->assertEquals($expected, $result); - } - - /** - * testRecursiveFindAllWithLimit method - * - * @return void - */ - public function testRecursiveFindAllWithLimit() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); - $TestModel = new Article(); - - $TestModel->hasMany['Comment']['limit'] = 2; - - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 1) )); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array(), - 'Tag' => array() - ) - ); - $this->assertEquals($expected, $result); - - $TestModel->hasMany['Comment']['limit'] = 1; - - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 3), - 'limit' => 1, - 'recursive' => 2 - )); - $expected = array( - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Attachment' => array( - 'id' => '1', - 'comment_id' => 5, - 'attachment' => 'attachment.zip', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ) - ) - ) - ); - $this->assertEquals($expected, $result); - } - - /** - * Testing availability of $this->findQueryType in Model callbacks - * - * @return void - */ - public function testFindQueryTypeInCallbacks() { - $this->loadFixtures('Comment'); - $Comment = new AgainModifiedComment(); - $comments = $Comment->find('all'); - $this->assertEquals('all', $comments[0]['Comment']['querytype']); - $comments = $Comment->find('first'); - $this->assertEquals('first', $comments['Comment']['querytype']); - } - - /** - * testVirtualFields() - * - * Test correct fetching of virtual fields - * currently is not possible to do Relation.virtualField - * - * @return void - */ - public function testVirtualFields() { - $this->loadFixtures('Post', 'Author'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('two' => "1 + 1"); - $result = $Post->find('first'); - $this->assertEquals(2, $result['Post']['two']); - - // SQL Server does not support operators in expressions - if (!($this->db instanceof Sqlserver)) { - $Post->Author->virtualFields = array('false' => '1 = 2'); - $result = $Post->find('first'); - $this->assertEquals(2, $result['Post']['two']); - $this->assertFalse((bool) $result['Author']['false']); + $this->assertEquals($expected, $result); } - $result = $Post->find('first', array('fields' => array('author_id'))); - $this->assertFalse(isset($result['Post']['two'])); - $this->assertFalse(isset($result['Author']['false'])); +/** + * testRead method + * + * @return void + */ + public function testRead() { + $this->loadFixtures('User', 'Article'); + $TestModel = new User(); - $result = $Post->find('first', array('fields' => array('author_id', 'two'))); - $this->assertEquals(2, $result['Post']['two']); - $this->assertFalse(isset($result['Author']['false'])); + $result = $TestModel->read(); + $this->assertFalse($result); - $result = $Post->find('first', array('fields' => array('two'))); - $this->assertEquals(2, $result['Post']['two']); - - $Post->id = 1; - $result = $Post->field('two'); - $this->assertEquals(2, $result); - - $result = $Post->find('first', array( - 'conditions' => array('two' => 2), - 'limit' => 1 + $TestModel->id = 2; + $result = $TestModel->read(); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' )); - $this->assertEquals(2, $result['Post']['two']); + $this->assertEquals($expected, $result); - $result = $Post->find('first', array( - 'conditions' => array('two <' => 3), - 'limit' => 1 + $result = $TestModel->read(null, 2); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' )); - $this->assertEquals(2, $result['Post']['two']); + $this->assertEquals($expected, $result); - $result = $Post->find('first', array( - 'conditions' => array('NOT' => array('two >' => 3)), - 'limit' => 1 + $TestModel->id = 2; + $result = $TestModel->read(array('id', 'user')); + $expected = array('User' => array('id' => '2', 'user' => 'nate')); + $this->assertEquals($expected, $result); + + $result = $TestModel->read('id, user', 2); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' )); - $this->assertEquals(2, $result['Post']['two']); + $this->assertEquals($expected, $result); - $dbo = $Post->getDataSource(); - $Post->virtualFields = array('other_field' => 'Post.id + 1'); - $result = $Post->find('first', array( - 'conditions' => array('other_field' => 3), - 'limit' => 1 - )); - $this->assertEquals(2, $result['Post']['id']); + $result = $TestModel->bindModel(array('hasMany' => array('Article'))); + $this->assertTrue($result); - $Post->order = null; + $TestModel->id = 1; + $result = $TestModel->read('id, user'); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Article' => array( + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + $this->assertEquals($expected, $result); + } - $Post->virtualFields = array('other_field' => 'Post.id + 1'); - $result = $Post->find('all', array( - 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) - )); - $this->assertEquals(4, $result[0][0]['other_field']); +/** + * testRecursiveRead method + * + * @return void + */ + public function testRecursiveRead() { + $this->loadFixtures( + 'User', + 'Article', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Featured', + 'ArticleFeatured' + ); + $TestModel = new User(); - ClassRegistry::flush(); - $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing')); - $Writing->virtualFields = array('two' => "1 + 1"); - $result = $Writing->find('first'); - $this->assertEquals(2, $result['Writing']['two']); + $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); + $this->assertTrue($result); - $Post->create(); - $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); - $result = $Post->field('other_field'); - $this->assertEquals(4, $result); - } + $TestModel->recursive = 0; + $result = $TestModel->read('id, user', 1); + $expected = array( + 'User' => array('id' => '1', 'user' => 'mariano'), + ); + $this->assertEquals($expected, $result); - /** - * testVirtualFieldsOrder() - * - * Test correct order on virtual fields - * - * @return void - */ - public function testVirtualFieldsOrder() { - $this->loadFixtures('Post', 'Author'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('other_field' => '10 - Post.id'); - $result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC'))); - $expected = array( - '3' => 'Third Post', - '2' => 'Second Post', - '1' => 'First Post' - ); - $this->assertEquals($expected, $result); + $TestModel->recursive = 1; + $result = $TestModel->read('id, user', 1); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Article' => array( + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + $this->assertEquals($expected, $result); - $result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC'))); - $expected = array( - '1' => 'First Post', - '2' => 'Second Post', - '3' => 'Third Post' - ); - $this->assertEquals($expected, $result); + $TestModel->recursive = 2; + $result = $TestModel->read('id, user', 3); + $expected = array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Article' => array( + array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))))); + $this->assertEquals($expected, $result); + } - $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id'); - $result = $Post->find('all', array( - 'order' => array('Post.id' => 'ASC') - )); - $result = Hash::extract($result, '{n}.Author.joined'); - $expected = array(1, 6, 3); - $this->assertEquals($expected, $result); + public function testRecursiveFindAll() { + $this->loadFixtures( + 'User', + 'Article', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Attachment', + 'ArticleFeatured', + 'ArticleFeaturedsTags', + 'Featured', + 'Category' + ); + $TestModel = new Article(); - $result = $Post->find('all', array('order' => array('Author.joined' => 'ASC'))); - $result = Hash::extract($result, '{n}.Author.joined'); - $expected = array(1, 3, 6); - $this->assertEquals($expected, $result); + $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); + $expected = array( + array( + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array(), + 'Tag' => array() + ) + ); + $this->assertEquals($expected, $result); - $result = $Post->find('all', array('order' => array('Author.joined' => 'DESC'))); - $result = Hash::extract($result, '{n}.Author.joined'); - $expected = array(6, 3, 1); - $this->assertEquals($expected, $result); - } - - /** - * testVirtualFieldsMysql() - * - * Test correct fetching of virtual fields - * currently is not possible to do Relation.virtualField - * - */ - public function testVirtualFieldsMysql() { - $this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFields test only compatible with Mysql.'); - - $this->loadFixtures('Post', 'Author'); - $Post = ClassRegistry::init('Post'); - - $Post->create(); - $Post->virtualFields = array( - 'low_title' => 'lower(Post.title)', - 'unique_test_field' => 'COUNT(Post.id)' - ); - - $expectation = array( - 'Post' => array( - 'low_title' => 'first post', - 'unique_test_field' => 1 - ) - ); - - $result = $Post->find('first', array( - 'fields' => array_keys($Post->virtualFields), - 'group' => array('low_title') + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 )); - $this->assertEquals($expectation, $result); + $expected = array( + array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Attachment' => array() + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + )))); - $Author = ClassRegistry::init('Author'); - $Author->virtualFields = array( - 'full_name' => 'CONCAT(Author.user, " ", Author.id)' - ); + $this->assertEquals($expected, $result); - $result = $Author->find('first', array( - 'conditions' => array('Author.user' => 'mariano'), - 'fields' => array('Author.password', 'Author.full_name'), - 'recursive' => -1 + $Featured = new Featured(); + + $Featured->recursive = 2; + $Featured->bindModel(array( + 'belongsTo' => array( + 'ArticleFeatured' => array( + 'conditions' => "ArticleFeatured.published = 'Y'", + 'fields' => 'id, title, user_id, published' + ) + ) )); - $this->assertTrue(isset($result['Author']['full_name'])); - $result = $Author->find('first', array( - 'conditions' => array('Author.user' => 'mariano'), - 'fields' => array('Author.full_name', 'Author.password'), - 'recursive' => -1 + $Featured->ArticleFeatured->unbindModel(array( + 'hasMany' => array('Attachment', 'Comment'), + 'hasAndBelongsToMany' => array('Tag')) + ); + + $orderBy = 'ArticleFeatured.id ASC'; + $result = $Featured->find('all', array( + 'order' => $orderBy, 'limit' => 3 )); - $this->assertTrue(isset($result['Author']['full_name'])); - } - /** - * test that virtual fields work when they don't contain functions. - * - * @return void - */ - public function testVirtualFieldAsAString() { - $this->loadFixtures('Post', 'Author'); - $Post = new Post(); - $Post->virtualFields = array( - 'writer' => 'Author.user' - ); - $result = $Post->find('first'); - $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s'); - } + $expected = array( + array( + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '1', + 'title' => 'First Article', + 'user_id' => '1', + 'published' => 'Y', + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Category' => array(), + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + )), + array( + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '2', + 'title' => 'Second Article', + 'user_id' => '3', + 'published' => 'Y', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Category' => array(), + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))); + $this->assertEquals($expected, $result); + } - /** - * test that isVirtualField will accept both aliased and non aliased fieldnames - * - * @return void - */ - public function testIsVirtualField() { - $this->loadFixtures('Post'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); +/** + * testRecursiveFindAllWithLimit method + * + * @return void + */ + public function testRecursiveFindAllWithLimit() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); + $TestModel = new Article(); - $this->assertTrue($Post->isVirtualField('other_field')); - $this->assertTrue($Post->isVirtualField('Post.other_field')); - $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.'); - $this->assertFalse($Post->isVirtualField('id')); - $this->assertFalse($Post->isVirtualField('Post.id')); - $this->assertFalse($Post->isVirtualField(array())); - } + $TestModel->hasMany['Comment']['limit'] = 2; - /** - * test that getting virtual fields works with and without model alias attached - * - * @return void - */ - public function testGetVirtualField() { - $this->loadFixtures('Post'); - $Post = ClassRegistry::init('Post'); - $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 1) + )); + $expected = array( + array( + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array(), + 'Tag' => array() + ) + ); + $this->assertEquals($expected, $result); - $this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']); - $this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']); - } + $TestModel->hasMany['Comment']['limit'] = 1; - /** - * test that checks for error when NOT condition passed in key and a 1 element array value - * - * @return void - */ - public function testNotInArrayWithOneValue() { - $this->loadFixtures('Article'); - $Article = new Article(); - $Article->recursive = -1; + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 + )); + $expected = array( + array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) + ) + ) + ); + $this->assertEquals($expected, $result); + } - $result = $Article->find( - 'all', array( - 'conditions' => array( - 'Article.id NOT' => array(1) - ) - ) - ); - $this->assertTrue(is_array($result) && !empty($result)); - } +/** + * Testing availability of $this->findQueryType in Model callbacks + * + * @return void + */ + public function testFindQueryTypeInCallbacks() { + $this->loadFixtures('Comment'); + $Comment = new AgainModifiedComment(); + $comments = $Comment->find('all'); + $this->assertEquals('all', $comments[0]['Comment']['querytype']); + $comments = $Comment->find('first'); + $this->assertEquals('first', $comments['Comment']['querytype']); + } - /** - * test custom find method - * - * @return void - */ - public function testfindCustom() { - $this->loadFixtures('Article'); - $Article = new CustomArticle(); - $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N'); - $Article->create($data); - $Article->save(null, false); - $this->assertEquals(4, $Article->id); +/** + * testVirtualFields() + * + * Test correct fetching of virtual fields + * currently is not possible to do Relation.virtualField + * + * @return void + */ + public function testVirtualFields() { + $this->loadFixtures('Post', 'Author'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('two' => "1 + 1"); + $result = $Post->find('first'); + $this->assertEquals(2, $result['Post']['two']); - $result = $Article->find('published'); - $this->assertEquals(3, count($result)); + // SQL Server does not support operators in expressions + if (!($this->db instanceof Sqlserver)) { + $Post->Author->virtualFields = array('false' => '1 = 2'); + $result = $Post->find('first'); + $this->assertEquals(2, $result['Post']['two']); + $this->assertFalse((bool)$result['Author']['false']); + } - $result = $Article->find('unPublished'); - $this->assertEquals(1, count($result)); - } + $result = $Post->find('first', array('fields' => array('author_id'))); + $this->assertFalse(isset($result['Post']['two'])); + $this->assertFalse(isset($result['Author']['false'])); - /** - * test after find callback on related model - * - * @return void - */ - public function testRelatedAfterFindCallback() { - $this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation'); - $ModelWithRelations = new ModelWithRelations(); + $result = $Post->find('first', array('fields' => array('author_id', 'two'))); + $this->assertEquals(2, $result['Post']['two']); + $this->assertFalse(isset($result['Author']['false'])); -// belongsTo Test - $ModelWithRelations->bindModel(array( - 'belongsTo' => array( - 'BelongsTo' => array( - 'className' => 'ModelRelated', - 'foreignKey' => 'related_id', - ) - ) - ) - ); - $results = $ModelWithRelations->find('all'); - $expected = array( - array( - 'ModelWithRelations' => array( - 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' - ), - 'BelongsTo' => array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1' - ) - ), - array( - 'ModelWithRelations' => array( - 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' - ), - 'BelongsTo' => array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2' - ) - ) - ); - $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail'); + $result = $Post->find('first', array('fields' => array('two'))); + $this->assertEquals(2, $result['Post']['two']); + + $Post->id = 1; + $result = $Post->field('two'); + $this->assertEquals(2, $result); + + $result = $Post->find('first', array( + 'conditions' => array('two' => 2), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['two']); + + $result = $Post->find('first', array( + 'conditions' => array('two <' => 3), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['two']); + + $result = $Post->find('first', array( + 'conditions' => array('NOT' => array('two >' => 3)), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['two']); + + $dbo = $Post->getDataSource(); + $Post->virtualFields = array('other_field' => 'Post.id + 1'); + $result = $Post->find('first', array( + 'conditions' => array('other_field' => 3), + 'limit' => 1 + )); + $this->assertEquals(2, $result['Post']['id']); + + $Post->virtualFields = array('other_field' => 'Post.id + 1'); + $result = $Post->find('all', array( + 'fields' => array($dbo->calculate($Post, 'max', array('other_field'))) + )); + $this->assertEquals(4, $result[0][0]['other_field']); + + ClassRegistry::flush(); + $Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing')); + $Writing->virtualFields = array('two' => "1 + 1"); + $result = $Writing->find('first'); + $this->assertEquals(2, $result['Writing']['two']); + + $Post->create(); + $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); + $result = $Post->field('other_field'); + $this->assertEquals(4, $result); + } + +/** + * testVirtualFieldsOrder() + * + * Test correct order on virtual fields + * + * @return void + */ + public function testVirtualFieldsOrder() { + $this->loadFixtures('Post', 'Author'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('other_field' => '10 - Post.id'); + $result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC'))); + $expected = array( + '3' => 'Third Post', + '2' => 'Second Post', + '1' => 'First Post' + ); + $this->assertEquals($expected, $result); + + $result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC'))); + $expected = array( + '1' => 'First Post', + '2' => 'Second Post', + '3' => 'Third Post' + ); + $this->assertEquals($expected, $result); + + $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id'); + $result = $Post->find('all', array( + 'order' => array('Post.id' => 'ASC') + )); + $result = Hash::extract($result, '{n}.Author.joined'); + $expected = array(1, 6, 3); + $this->assertEquals($expected, $result); + + $result = $Post->find('all', array('order' => array('Author.joined' => 'ASC'))); + $result = Hash::extract($result, '{n}.Author.joined'); + $expected = array(1, 3, 6); + $this->assertEquals($expected, $result); + + $result = $Post->find('all', array('order' => array('Author.joined' => 'DESC'))); + $result = Hash::extract($result, '{n}.Author.joined'); + $expected = array(6, 3, 1); + $this->assertEquals($expected, $result); + } + +/** + * testVirtualFieldsMysql() + * + * Test correct fetching of virtual fields + * currently is not possible to do Relation.virtualField + * + */ + public function testVirtualFieldsMysql() { + $this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFields test only compatible with Mysql.'); + + $this->loadFixtures('Post', 'Author'); + $Post = ClassRegistry::init('Post'); + + $Post->create(); + $Post->virtualFields = array( + 'low_title' => 'lower(Post.title)', + 'unique_test_field' => 'COUNT(Post.id)' + ); + + $expectation = array( + 'Post' => array( + 'low_title' => 'first post', + 'unique_test_field' => 1 + ) + ); + + $result = $Post->find('first', array( + 'fields' => array_keys($Post->virtualFields), + 'group' => array('low_title') + )); + + $this->assertEquals($expectation, $result); + + $Author = ClassRegistry::init('Author'); + $Author->virtualFields = array( + 'full_name' => 'CONCAT(Author.user, " ", Author.id)' + ); + + $result = $Author->find('first', array( + 'conditions' => array('Author.user' => 'mariano'), + 'fields' => array('Author.password', 'Author.full_name'), + 'recursive' => -1 + )); + $this->assertTrue(isset($result['Author']['full_name'])); + + $result = $Author->find('first', array( + 'conditions' => array('Author.user' => 'mariano'), + 'fields' => array('Author.full_name', 'Author.password'), + 'recursive' => -1 + )); + $this->assertTrue(isset($result['Author']['full_name'])); + } + +/** + * test that virtual fields work when they don't contain functions. + * + * @return void + */ + public function testVirtualFieldAsAString() { + $this->loadFixtures('Post', 'Author'); + $Post = new Post(); + $Post->virtualFields = array( + 'writer' => 'Author.user' + ); + $result = $Post->find('first'); + $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s'); + } + +/** + * test that isVirtualField will accept both aliased and non aliased fieldnames + * + * @return void + */ + public function testIsVirtualField() { + $this->loadFixtures('Post'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); + + $this->assertTrue($Post->isVirtualField('other_field')); + $this->assertTrue($Post->isVirtualField('Post.other_field')); + $this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.'); + $this->assertFalse($Post->isVirtualField('id')); + $this->assertFalse($Post->isVirtualField('Post.id')); + $this->assertFalse($Post->isVirtualField(array())); + } + +/** + * test that getting virtual fields works with and without model alias attached + * + * @return void + */ + public function testGetVirtualField() { + $this->loadFixtures('Post'); + $Post = ClassRegistry::init('Post'); + $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1'); + + $this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']); + $this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']); + } + +/** + * test that checks for error when NOT condition passed in key and a 1 element array value + * + * @return void + */ + public function testNotInArrayWithOneValue() { + $this->loadFixtures('Article'); + $Article = new Article(); + $Article->recursive = -1; + + $result = $Article->find( + 'all', + array( + 'conditions' => array( + 'Article.id NOT' => array(1) + ) + ) + ); + $this->assertTrue(is_array($result) && !empty($result)); + } + +/** + * test custom find method + * + * @return void + */ + public function testfindCustom() { + $this->loadFixtures('Article'); + $Article = new CustomArticle(); + $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N'); + $Article->create($data); + $Article->save(null, false); + $this->assertEquals(4, $Article->id); + + $result = $Article->find('published'); + $this->assertEquals(3, count($result)); + + $result = $Article->find('unPublished'); + $this->assertEquals(1, count($result)); + } + +/** +* test after find callback on related model +* +* @return void +*/ + public function testRelatedAfterFindCallback() { + $this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation'); + $ModelWithRelations = new ModelWithRelations(); + + $ModelWithRelations->bindModel(array( + 'belongsTo' => array( + 'BelongsTo' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'related_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'BelongsTo' => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'BelongsTo' => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail'); -// hasOne test - $ModelWithRelations->bindModel(array( - 'hasOne' => array( - 'HasOne' => array( - 'className' => 'ModelRelated', - 'foreignKey' => 'primary_id', - ) - ) - ) - ); - $results = $ModelWithRelations->find('all'); - $expected = array( - array( - 'ModelWithRelations' => array( - 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' - ), - 'HasOne' => array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1' - ) - ), - array( - 'ModelWithRelations' => array( - 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' - ), - 'HasOne' => array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2' - ) - ) - ); - $this->assertEquals($expected, $results, 'Model related with hasOne afterFind callback fail'); + $ModelWithRelations->bindModel(array( + 'hasOne' => array( + 'HasOne' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'primary_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasOne' => array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasOne' => array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasOne afterFind callback fail'); -// hasMany test - $ModelWithRelations->bindModel(array( - 'hasMany' => array( - 'HasMany' => array( - 'className' => 'ModelRelated', - 'foreignKey' => 'primary_id', - ) - ) - ) - ); - $results = $ModelWithRelations->find('all'); + $ModelWithRelations->bindModel(array( + 'hasMany' => array( + 'HasMany' => array( + 'className' => 'ModelRelated', + 'foreignKey' => 'primary_id', + ) + ) + ) + ); + $results = $ModelWithRelations->find('all'); - $expected = array( - array( - 'ModelWithRelations' => array( - 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' - ), - 'HasMany' => array( - (int) 0 => array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1' - ) - ) - ), - array( - 'ModelWithRelations' => array( - 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' - ), - 'HasMany' => array( - (int) 0 => array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2' - ) - ) - ) - ); - $this->assertEquals($expected, $results, 'Model related with hasMany afterFind callback fail'); - -// hasAndBelongsToMany test - $ModelWithRelations->bindModel(array( - 'hasAndBelongsToMany' => array( - 'HasAndBelongsToMany' => array( - 'className' => 'ModelRelated', - 'with' => 'ModelHabtmRelation', - 'foreignKey' => 'primary_id', - 'associationForeignKey' => 'related_id', - ) - ) - ) - ); - $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasMany' => array( + array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1' + ) + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasMany' => array( + array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2' + ) + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasMany afterFind callback fail'); - $expected = array( - array( - 'ModelWithRelations' => array( - 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' - ), - 'HasAndBelongsToMany' => array( - (int) 0 => array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1', - 'ModelHabtmRelation' => array( - 'id' => '1', - 'primary_id' => '1', - 'related_id' => '1' + $ModelWithRelations->bindModel(array( + 'hasAndBelongsToMany' => array( + 'HasAndBelongsToMany' => array( + 'className' => 'ModelRelated', + 'with' => 'ModelHabtmRelation', + 'foreignKey' => 'primary_id', + 'associationForeignKey' => 'related_id', + ) ) - ), - (int) 1 => array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2', - 'ModelHabtmRelation' => array( - 'id' => '2', - 'primary_id' => '1', - 'related_id' => '2' - ) - ) - ) - ), - array( - 'ModelWithRelations' => array( - 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' - ), - 'HasAndBelongsToMany' => array( - (int) 0 => array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1', - 'ModelHabtmRelation' => array( - 'id' => '3', - 'primary_id' => '2', - 'related_id' => '1' - ) - ), - (int) 1 => array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2', - 'ModelHabtmRelation' => array( - 'id' => '4', - 'primary_id' => '2', - 'related_id' => '2' - ) - ) - ) - ) - ); - $this->assertEquals($expected, $results, 'Model related with hasAndBelongsToMany afterFind callback fail'); - } + ) + ); + $results = $ModelWithRelations->find('all'); + $expected = array( + array( + 'ModelWithRelations' => array( + 'id' => '1', + 'name' => 'First record', + 'related_id' => '1' + ), + 'HasAndBelongsToMany' => array( + array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1', + 'ModelHabtmRelation' => array( + 'id' => '1', + 'primary_id' => '1', + 'related_id' => '1' + ) + ), + array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2', + 'ModelHabtmRelation' => array( + 'id' => '2', + 'primary_id' => '1', + 'related_id' => '2' + ) + ) + ) + ), + array( + 'ModelWithRelations' => array( + 'id' => '2', + 'name' => 'Second record', + 'related_id' => '2' + ), + 'HasAndBelongsToMany' => array( + array( + 'id' => '1', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '1', + 'ModelHabtmRelation' => array( + 'id' => '3', + 'primary_id' => '2', + 'related_id' => '1' + ) + ), + array( + 'id' => '2', + 'name' => 'Successfuly changed in AfterFind', + 'primary_id' => '2', + 'ModelHabtmRelation' => array( + 'id' => '4', + 'primary_id' => '2', + 'related_id' => '2' + ) + ) + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with hasAndBelongsToMany afterFind callback fail'); + } } diff --git a/lib/Cake/Test/Case/Model/ModelTestBase.php b/lib/Cake/Test/Case/Model/ModelTestBase.php index 6f444e338..73ae9c606 100644 --- a/lib/Cake/Test/Case/Model/ModelTestBase.php +++ b/lib/Cake/Test/Case/Model/ModelTestBase.php @@ -1,5 +1,4 @@ debug = Configure::read('debug'); - } - - /** - * tearDown method - * - * @return void - */ - public function tearDown() { - parent::tearDown(); - Configure::write('debug', $this->debug); - ClassRegistry::flush(); - } +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + $this->debug = Configure::read('debug'); + } +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + parent::tearDown(); + Configure::write('debug', $this->debug); + ClassRegistry::flush(); + } } diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index 85d474d33..f91d79a81 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -1,5 +1,4 @@ true); +/** + * findMethods property + * + * @var array + */ + public $findMethods = array('published' => true); - /** - * useDbConfig property - * - * @var array - */ - public $useDbConfig = 'test'; +/** + * useDbConfig property + * + * @var array + */ + public $useDbConfig = 'test'; - /** - * _findPublished custom find - * - * @return array - */ - protected function _findPublished($state, $query, $results = array()) { - if ($state === 'before') { - $query['conditions']['published'] = 'Y'; - return $query; +/** + * _findPublished custom find + * + * @return array + */ + protected function _findPublished($state, $query, $results = array()) { + if ($state === 'before') { + $query['conditions']['published'] = 'Y'; + return $query; + } + return $results; } - return $results; - } } @@ -65,33 +65,33 @@ class AppModel extends Model { */ class Test extends CakeTestModel { - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * name property - * - * @var string - */ - public $name = 'Test'; +/** + * name property + * + * @var string + */ + public $name = 'Test'; - /** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } @@ -102,34 +102,33 @@ class Test extends CakeTestModel { */ class TestAlias extends CakeTestModel { - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * name property - * - * @var string - */ - public $name = 'TestAlias'; - - /** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * name property + * + * @var string + */ + public $name = 'TestAlias'; +/** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '1', 'length' => '8', 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'notes' => array('type' => 'text', 'null' => '1', 'default' => 'write some notes here', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); } /** @@ -139,56 +138,56 @@ class TestAlias extends CakeTestModel { */ class TestValidate extends CakeTestModel { - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * name property - * - * @var string - */ - public $name = 'TestValidate'; +/** + * name property + * + * @var string + */ + public $name = 'TestValidate'; - /** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'title' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'body' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => ''), - 'number' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'modified' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'title' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'body' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => ''), + 'number' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'modified' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); - /** - * validateNumber method - * - * @param mixed $value - * @param mixed $options - * @return void - */ - public function validateNumber($value, $options) { - $options = array_merge(array('min' => 0, 'max' => 100), $options); - $valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']); - return $valid; - } +/** + * validateNumber method + * + * @param mixed $value + * @param mixed $options + * @return void + */ + public function validateNumber($value, $options) { + $options = array_merge(array('min' => 0, 'max' => 100), $options); + $valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']); + return $valid; + } - /** - * validateTitle method - * - * @param mixed $value - * @return void - */ - public function validateTitle($value) { - return (!empty($value) && strpos(strtolower($value['title']), 'title-') === 0); - } +/** + * validateTitle method + * + * @param mixed $value + * @return void + */ + public function validateTitle($value) { + return (!empty($value) && strpos(strtolower($value['title']), 'title-') === 0); + } } @@ -199,34 +198,34 @@ class TestValidate extends CakeTestModel { */ class User extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'User'; +/** + * name property + * + * @var string + */ + public $name = 'User'; - /** - * validate property - * - * @var array - */ - public $validate = array('user' => 'notEmpty', 'password' => 'notEmpty'); +/** + * validate property + * + * @var array + */ + public $validate = array('user' => 'notEmpty', 'password' => 'notEmpty'); - /** - * beforeFind() callback used to run ContainableBehaviorTest::testLazyLoad() - * - * @return bool - * @throws Exception - */ - public function beforeFind($queryData) { - if (!empty($queryData['lazyLoad'])) { - if (!isset($this->Article, $this->Comment, $this->ArticleFeatured)) { - throw new Exception('Unavailable associations'); - } +/** + * beforeFind() callback used to run ContainableBehaviorTest::testLazyLoad() + * + * @return bool + * @throws Exception + */ + public function beforeFind($queryData) { + if (!empty($queryData['lazyLoad'])) { + if (!isset($this->Article, $this->Comment, $this->ArticleFeatured)) { + throw new Exception('Unavailable associations'); + } + } + return true; } - return true; - } } @@ -237,73 +236,73 @@ class User extends CakeTestModel { */ class Article extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Article'; +/** + * name property + * + * @var string + */ + public $name = 'Article'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Comment' => array('dependent' => true)); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Comment' => array('dependent' => true)); - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Tag'); +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Tag'); - /** - * validate property - * - * @var array - */ - public $validate = array( - 'user_id' => 'numeric', - 'title' => array('required' => false, 'rule' => 'notEmpty'), - 'body' => array('required' => false, 'rule' => 'notEmpty'), - ); +/** + * validate property + * + * @var array + */ + public $validate = array( + 'user_id' => 'numeric', + 'title' => array('required' => false, 'rule' => 'notEmpty'), + 'body' => array('required' => false, 'rule' => 'notEmpty'), + ); - /** - * beforeSaveReturn property - * - * @var bool true - */ - public $beforeSaveReturn = true; +/** + * beforeSaveReturn property + * + * @var bool true + */ + public $beforeSaveReturn = true; - /** - * beforeSave method - * - * @return void - */ - public function beforeSave($options = array()) { - return $this->beforeSaveReturn; - } - - /** - * titleDuplicate method - * - * @param string $title - * @return void - */ - public static function titleDuplicate($title) { - if ($title === 'My Article Title') { - return false; +/** + * beforeSave method + * + * @return void + */ + public function beforeSave($options = array()) { + return $this->beforeSaveReturn; + } + +/** + * titleDuplicate method + * + * @param string $title + * @return void + */ + public static function titleDuplicate($title) { + if ($title === 'My Article Title') { + return false; + } + return true; } - return true; - } } @@ -315,14 +314,15 @@ class Article extends CakeTestModel { */ class BeforeDeleteComment extends CakeTestModel { - public $name = 'BeforeDeleteComment'; - public $useTable = 'comments'; + public $name = 'BeforeDeleteComment'; - public function beforeDelete($cascade = true) { - $db = $this->getDataSource(); - $db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3))); - return true; - } + public $useTable = 'comments'; + + public function beforeDelete($cascade = true) { + $db = $this->getDataSource(); + $db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3))); + return true; + } } @@ -333,19 +333,19 @@ class BeforeDeleteComment extends CakeTestModel { */ class NumericArticle extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'NumericArticle'; +/** + * name property + * + * @var string + */ + public $name = 'NumericArticle'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'numeric_articles'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'numeric_articles'; } @@ -356,26 +356,26 @@ class NumericArticle extends CakeTestModel { */ class Article10 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Article10'; +/** + * name property + * + * @var string + */ + public $name = 'Article10'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'articles'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'articles'; - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Comment' => array('dependent' => true, 'exclusive' => true)); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Comment' => array('dependent' => true, 'exclusive' => true)); } @@ -386,47 +386,47 @@ class Article10 extends CakeTestModel { */ class ArticleFeatured extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ArticleFeatured'; +/** + * name property + * + * @var string + */ + public $name = 'ArticleFeatured'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User', 'Category'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User', 'Category'); - /** - * hasOne property - * - * @var array - */ - public $hasOne = array('Featured'); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array('Featured'); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Comment' => array('className' => 'Comment', 'dependent' => true)); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Comment' => array('className' => 'Comment', 'dependent' => true)); - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Tag'); +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Tag'); - /** - * validate property - * - * @var array - */ - public $validate = array('user_id' => 'numeric', 'title' => 'notEmpty', 'body' => 'notEmpty'); +/** + * validate property + * + * @var array + */ + public $validate = array('user_id' => 'numeric', 'title' => 'notEmpty', 'body' => 'notEmpty'); } @@ -437,20 +437,19 @@ class ArticleFeatured extends CakeTestModel { */ class Featured extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Featured'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('ArticleFeatured', 'Category'); +/** + * name property + * + * @var string + */ + public $name = 'Featured'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('ArticleFeatured', 'Category'); } /** @@ -460,13 +459,12 @@ class Featured extends CakeTestModel { */ class Tag extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Tag'; - +/** + * name property + * + * @var string + */ + public $name = 'Tag'; } /** @@ -476,13 +474,12 @@ class Tag extends CakeTestModel { */ class ArticlesTag extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ArticlesTag'; - +/** + * name property + * + * @var string + */ + public $name = 'ArticlesTag'; } /** @@ -492,13 +489,12 @@ class ArticlesTag extends CakeTestModel { */ class ArticleFeaturedsTag extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ArticleFeaturedsTag'; - +/** + * name property + * + * @var string + */ + public $name = 'ArticleFeaturedsTag'; } /** @@ -508,27 +504,26 @@ class ArticleFeaturedsTag extends CakeTestModel { */ class Comment extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Comment'; +/** + * name property + * + * @var string + */ + public $name = 'Comment'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Article', 'User'); - - /** - * hasOne property - * - * @var array - */ - public $hasOne = array('Attachment' => array('dependent' => true)); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Article', 'User'); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array('Attachment' => array('dependent' => true)); } /** @@ -538,48 +533,48 @@ class Comment extends CakeTestModel { */ class ModifiedComment extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Comment'; +/** + * name property + * + * @var string + */ + public $name = 'Comment'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'comments'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'comments'; - /** - * Property used to toggle filtering of results - * - * @var boolean - */ - public $remove = false; +/** + * Property used to toggle filtering of results + * + * @var boolean + */ + public $remove = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Article'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Article'); - /** - * afterFind callback - * - * @return void - */ - public function afterFind($results, $primary = false) { - if (isset($results[0])) { - $results[0]['Comment']['callback'] = 'Fire'; +/** + * afterFind callback + * + * @return void + */ + public function afterFind($results, $primary = false) { + if (isset($results[0])) { + $results[0]['Comment']['callback'] = 'Fire'; + } + if ($this->remove) { + return array(); + } + return $results; } - if ($this->remove) { - return array(); - } - return $results; - } } @@ -590,38 +585,38 @@ class ModifiedComment extends CakeTestModel { */ class AgainModifiedComment extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Comment'; +/** + * name property + * + * @var string + */ + public $name = 'Comment'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'comments'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'comments'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Article'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Article'); - /** - * afterFind callback - * - * @return void - */ - public function afterFind($results, $primary = false) { - if (isset($results[0])) { - $results[0]['Comment']['querytype'] = $this->findQueryType; +/** + * afterFind callback + * + * @return void + */ + public function afterFind($results, $primary = false) { + if (isset($results[0])) { + $results[0]['Comment']['querytype'] = $this->findQueryType; + } + return $results; } - return $results; - } } @@ -632,15 +627,14 @@ class AgainModifiedComment extends CakeTestModel { */ class MergeVarPluginAppModel extends AppModel { - /** - * actsAs parameter - * - * @var array - */ - public $actsAs = array( - 'Containable' - ); - +/** + * actsAs parameter + * + * @var array + */ + public $actsAs = array( + 'Containable' + ); } /** @@ -650,22 +644,21 @@ class MergeVarPluginAppModel extends AppModel { */ class MergeVarPluginPost extends MergeVarPluginAppModel { - /** - * actsAs parameter - * - * @var array - */ - public $actsAs = array( - 'Tree' - ); - - /** - * useTable parameter - * - * @var string - */ - public $useTable = 'posts'; +/** + * actsAs parameter + * + * @var array + */ + public $actsAs = array( + 'Tree' + ); +/** + * useTable parameter + * + * @var string + */ + public $useTable = 'posts'; } /** @@ -675,22 +668,21 @@ class MergeVarPluginPost extends MergeVarPluginAppModel { */ class MergeVarPluginComment extends MergeVarPluginAppModel { - /** - * actsAs parameter - * - * @var array - */ - public $actsAs = array( - 'Containable' => array('some_settings') - ); - - /** - * useTable parameter - * - * @var string - */ - public $useTable = 'comments'; +/** + * actsAs parameter + * + * @var array + */ + public $actsAs = array( + 'Containable' => array('some_settings') + ); +/** + * useTable parameter + * + * @var string + */ + public $useTable = 'comments'; } /** @@ -700,20 +692,19 @@ class MergeVarPluginComment extends MergeVarPluginAppModel { */ class Attachment extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Attachment'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Comment'); +/** + * name property + * + * @var string + */ + public $name = 'Attachment'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Comment'); } /** @@ -723,31 +714,31 @@ class Attachment extends CakeTestModel { */ class ModifiedAttachment extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ModifiedAttachment'; +/** + * name property + * + * @var string + */ + public $name = 'ModifiedAttachment'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'attachments'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'attachments'; - /** - * afterFind callback - * - * @return void - */ - public function afterFind($results, $primary = false) { - if (isset($results['id'])) { - $results['callback'] = 'Fired'; +/** + * afterFind callback + * + * @return void + */ + public function afterFind($results, $primary = false) { + if (isset($results['id'])) { + $results['callback'] = 'Fired'; + } + return $results; } - return $results; - } } @@ -758,13 +749,12 @@ class ModifiedAttachment extends CakeTestModel { */ class Category extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Category'; - +/** + * name property + * + * @var string + */ + public $name = 'Category'; } /** @@ -774,20 +764,19 @@ class Category extends CakeTestModel { */ class CategoryThread extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'CategoryThread'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('ParentCategory' => array('className' => 'CategoryThread', 'foreignKey' => 'parent_id')); +/** + * name property + * + * @var string + */ + public $name = 'CategoryThread'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('ParentCategory' => array('className' => 'CategoryThread', 'foreignKey' => 'parent_id')); } /** @@ -797,41 +786,40 @@ class CategoryThread extends CakeTestModel { */ class Apple extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Apple'; +/** + * name property + * + * @var string + */ + public $name = 'Apple'; - /** - * validate property - * - * @var array - */ - public $validate = array('name' => 'notEmpty'); +/** + * validate property + * + * @var array + */ + public $validate = array('name' => 'notEmpty'); - /** - * hasOne property - * - * @var array - */ - public $hasOne = array('Sample'); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array('Sample'); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Child' => array('className' => 'Apple', 'dependent' => true)); - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Parent' => array('className' => 'Apple', 'foreignKey' => 'apple_id')); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Child' => array('className' => 'Apple', 'dependent' => true)); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Parent' => array('className' => 'Apple', 'foreignKey' => 'apple_id')); } /** @@ -841,20 +829,19 @@ class Apple extends CakeTestModel { */ class Sample extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Sample'; - - /** - * belongsTo property - * - * @var string - */ - public $belongsTo = 'Apple'; +/** + * name property + * + * @var string + */ + public $name = 'Sample'; +/** + * belongsTo property + * + * @var string + */ + public $belongsTo = 'Apple'; } /** @@ -864,20 +851,19 @@ class Sample extends CakeTestModel { */ class AnotherArticle extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'AnotherArticle'; - - /** - * hasMany property - * - * @var string - */ - public $hasMany = 'Home'; +/** + * name property + * + * @var string + */ + public $name = 'AnotherArticle'; +/** + * hasMany property + * + * @var string + */ + public $hasMany = 'Home'; } /** @@ -887,20 +873,19 @@ class AnotherArticle extends CakeTestModel { */ class Advertisement extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Advertisement'; - - /** - * hasMany property - * - * @var string - */ - public $hasMany = 'Home'; +/** + * name property + * + * @var string + */ + public $name = 'Advertisement'; +/** + * hasMany property + * + * @var string + */ + public $hasMany = 'Home'; } /** @@ -910,20 +895,19 @@ class Advertisement extends CakeTestModel { */ class Home extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Home'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('AnotherArticle', 'Advertisement'); +/** + * name property + * + * @var string + */ + public $name = 'Home'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('AnotherArticle', 'Advertisement'); } /** @@ -933,31 +917,31 @@ class Home extends CakeTestModel { */ class Post extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Post'; +/** + * name property + * + * @var string + */ + public $name = 'Post'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Author'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Author'); - public function beforeFind($queryData) { - if (isset($queryData['connection'])) { - $this->useDbConfig = $queryData['connection']; + public function beforeFind($queryData) { + if (isset($queryData['connection'])) { + $this->useDbConfig = $queryData['connection']; + } + return true; } - return true; - } - public function afterFind($results, $primary = false) { - $this->useDbConfig = 'test'; - return $results; - } + public function afterFind($results, $primary = false) { + $this->useDbConfig = 'test'; + return $results; + } } @@ -968,30 +952,30 @@ class Post extends CakeTestModel { */ class Author extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Author'; +/** + * name property + * + * @var string + */ + public $name = 'Author'; - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Post'); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Post'); - /** - * afterFind method - * - * @param array $results - * @return void - */ - public function afterFind($results, $primary = false) { - $results[0]['Author']['test'] = 'working'; - return $results; - } +/** + * afterFind method + * + * @param array $results + * @return void + */ + public function afterFind($results, $primary = false) { + $results[0]['Author']['test'] = 'working'; + return $results; + } } @@ -1002,25 +986,25 @@ class Author extends CakeTestModel { */ class ModifiedAuthor extends Author { - /** - * name property - * - * @var string - */ - public $name = 'Author'; +/** + * name property + * + * @var string + */ + public $name = 'Author'; - /** - * afterFind method - * - * @param array $results - * @return void - */ - public function afterFind($results, $primary = false) { - foreach ($results as $index => $result) { - $results[$index]['Author']['user'] .= ' (CakePHP)'; +/** + * afterFind method + * + * @param array $results + * @return void + */ + public function afterFind($results, $primary = false) { + foreach ($results as $index => $result) { + $results[$index]['Author']['user'] .= ' (CakePHP)'; + } + return $results; } - return $results; - } } @@ -1031,20 +1015,19 @@ class ModifiedAuthor extends Author { */ class Project extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Project'; - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Thread'); +/** + * name property + * + * @var string + */ + public $name = 'Project'; +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Thread'); } /** @@ -1054,27 +1037,26 @@ class Project extends CakeTestModel { */ class Thread extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Thread'; +/** + * name property + * + * @var string + */ + public $name = 'Thread'; - /** - * hasMany property - * - * @var array - */ - public $belongsTo = array('Project'); - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Message'); +/** + * hasMany property + * + * @var array + */ + public $belongsTo = array('Project'); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Message'); } /** @@ -1084,20 +1066,19 @@ class Thread extends CakeTestModel { */ class Message extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Message'; - - /** - * hasOne property - * - * @var array - */ - public $hasOne = array('Bid'); +/** + * name property + * + * @var string + */ + public $name = 'Message'; +/** + * hasOne property + * + * @var array + */ + public $hasOne = array('Bid'); } /** @@ -1107,20 +1088,19 @@ class Message extends CakeTestModel { */ class Bid extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Bid'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Message'); +/** + * name property + * + * @var string + */ + public $name = 'Bid'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Message'); } /** @@ -1130,32 +1110,31 @@ class Bid extends CakeTestModel { */ class BiddingMessage extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'BiddingMessage'; +/** + * name property + * + * @var string + */ + public $name = 'BiddingMessage'; - /** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'bidding'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Bidding' => array( - 'foreignKey' => false, - 'conditions' => array('BiddingMessage.bidding = Bidding.bid') - ) - ); +/** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'bidding'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Bidding' => array( + 'foreignKey' => false, + 'conditions' => array('BiddingMessage.bidding = Bidding.bid') + ) + ); } /** @@ -1165,26 +1144,25 @@ class BiddingMessage extends CakeTestModel { */ class Bidding extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Bidding'; - - /** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'BiddingMessage' => array( - 'foreignKey' => false, - 'conditions' => array('BiddingMessage.bidding = Bidding.bid'), - 'dependent' => true - ) - ); +/** + * name property + * + * @var string + */ + public $name = 'Bidding'; +/** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'BiddingMessage' => array( + 'foreignKey' => false, + 'conditions' => array('BiddingMessage.bidding = Bidding.bid'), + 'dependent' => true + ) + ); } /** @@ -1194,57 +1172,57 @@ class Bidding extends CakeTestModel { */ class NodeAfterFind extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'NodeAfterFind'; +/** + * name property + * + * @var string + */ + public $name = 'NodeAfterFind'; - /** - * validate property - * - * @var array - */ - public $validate = array('name' => 'notEmpty'); +/** + * validate property + * + * @var array + */ + public $validate = array('name' => 'notEmpty'); - /** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; - /** - * hasOne property - * - * @var array - */ - public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); - /** - * afterFind method - * - * @param mixed $results - * @return array - */ - public function afterFind($results, $primary = false) { - return $results; - } +/** + * afterFind method + * + * @param mixed $results + * @return array + */ + public function afterFind($results, $primary = false) { + return $results; + } } @@ -1255,27 +1233,26 @@ class NodeAfterFind extends CakeTestModel { */ class NodeAfterFindSample extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'NodeAfterFindSample'; +/** + * name property + * + * @var string + */ + public $name = 'NodeAfterFindSample'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'samples'; - - /** - * belongsTo property - * - * @var string - */ - public $belongsTo = 'NodeAfterFind'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'samples'; +/** + * belongsTo property + * + * @var string + */ + public $belongsTo = 'NodeAfterFind'; } /** @@ -1285,48 +1262,47 @@ class NodeAfterFindSample extends CakeTestModel { */ class NodeNoAfterFind extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'NodeAfterFind'; +/** + * name property + * + * @var string + */ + public $name = 'NodeAfterFind'; - /** - * validate property - * - * @var array - */ - public $validate = array('name' => 'notEmpty'); +/** + * validate property + * + * @var array + */ + public $validate = array('name' => 'notEmpty'); - /** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; - /** - * hasOne property - * - * @var array - */ - public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array('Sample' => array('className' => 'NodeAfterFindSample')); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Child' => array('className' => 'NodeAfterFind', 'dependent' => true)); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Parent' => array('className' => 'NodeAfterFind', 'foreignKey' => 'apple_id')); } /** @@ -1336,28 +1312,27 @@ class NodeNoAfterFind extends CakeTestModel { */ class Node extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Node'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array( - 'ParentNode' => array( - 'className' => 'Node', - 'joinTable' => 'dependency', - 'with' => 'Dependency', - 'foreignKey' => 'child_id', - 'associationForeignKey' => 'parent_id', - ) - ); +/** + * name property + * + * @var string + */ + public $name = 'Node'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array( + 'ParentNode' => array( + 'className' => 'Node', + 'joinTable' => 'dependency', + 'with' => 'Dependency', + 'foreignKey' => 'child_id', + 'associationForeignKey' => 'parent_id', + ) + ); } /** @@ -1367,13 +1342,12 @@ class Node extends CakeTestModel { */ class Dependency extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Dependency'; - +/** + * name property + * + * @var string + */ + public $name = 'Dependency'; } /** @@ -1383,27 +1357,26 @@ class Dependency extends CakeTestModel { */ class ModelA extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ModelA'; +/** + * name property + * + * @var string + */ + public $name = 'ModelA'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('ModelB', 'ModelC'); +/** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('ModelB', 'ModelC'); } /** @@ -1413,27 +1386,26 @@ class ModelA extends CakeTestModel { */ class ModelB extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ModelB'; +/** + * name property + * + * @var string + */ + public $name = 'ModelB'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'messages'; - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('ModelD'); +/** + * useTable property + * + * @var string + */ + public $useTable = 'messages'; +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('ModelD'); } /** @@ -1443,27 +1415,26 @@ class ModelB extends CakeTestModel { */ class ModelC extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ModelC'; +/** + * name property + * + * @var string + */ + public $name = 'ModelC'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'bids'; - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('ModelD'); +/** + * useTable property + * + * @var string + */ + public $useTable = 'bids'; +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('ModelD'); } /** @@ -1473,20 +1444,19 @@ class ModelC extends CakeTestModel { */ class ModelD extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ModelD'; - - /** - * useTable property - * - * @var string - */ - public $useTable = 'threads'; +/** + * name property + * + * @var string + */ + public $name = 'ModelD'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'threads'; } /** @@ -1496,20 +1466,19 @@ class ModelD extends CakeTestModel { */ class Something extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Something'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('SomethingElse' => array('with' => array('JoinThing' => array('doomed')))); +/** + * name property + * + * @var string + */ + public $name = 'Something'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('SomethingElse' => array('with' => array('JoinThing' => array('doomed')))); } /** @@ -1519,20 +1488,19 @@ class Something extends CakeTestModel { */ class SomethingElse extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'SomethingElse'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Something' => array('with' => 'JoinThing')); +/** + * name property + * + * @var string + */ + public $name = 'SomethingElse'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Something' => array('with' => 'JoinThing')); } /** @@ -1542,20 +1510,19 @@ class SomethingElse extends CakeTestModel { */ class JoinThing extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'JoinThing'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Something', 'SomethingElse'); +/** + * name property + * + * @var string + */ + public $name = 'JoinThing'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Something', 'SomethingElse'); } /** @@ -1565,20 +1532,19 @@ class JoinThing extends CakeTestModel { */ class Portfolio extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Portfolio'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Item'); +/** + * name property + * + * @var string + */ + public $name = 'Portfolio'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Item'); } /** @@ -1588,27 +1554,26 @@ class Portfolio extends CakeTestModel { */ class Item extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Item'; +/** + * name property + * + * @var string + */ + public $name = 'Item'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Syfile' => array('counterCache' => true)); - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Portfolio' => array('unique' => false)); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Syfile' => array('counterCache' => true)); +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Portfolio' => array('unique' => false)); } /** @@ -1618,13 +1583,12 @@ class Item extends CakeTestModel { */ class ItemsPortfolio extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ItemsPortfolio'; - +/** + * name property + * + * @var string + */ + public $name = 'ItemsPortfolio'; } /** @@ -1634,20 +1598,19 @@ class ItemsPortfolio extends CakeTestModel { */ class Syfile extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Syfile'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Image'); +/** + * name property + * + * @var string + */ + public $name = 'Syfile'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Image'); } /** @@ -1657,13 +1620,12 @@ class Syfile extends CakeTestModel { */ class Image extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Image'; - +/** + * name property + * + * @var string + */ + public $name = 'Image'; } /** @@ -1673,38 +1635,37 @@ class Image extends CakeTestModel { */ class DeviceType extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'DeviceType'; +/** + * name property + * + * @var string + */ + public $name = 'DeviceType'; - /** - * order property - * - * @var array - */ - public $order = array('DeviceType.order' => 'ASC'); +/** + * order property + * + * @var array + */ + public $order = array('DeviceType.order' => 'ASC'); - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', - 'Image' => array('className' => 'Document'), - 'Extra1' => array('className' => 'Document'), - 'Extra2' => array('className' => 'Document')); - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Device' => array('order' => array('Device.id' => 'ASC'))); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', + 'Image' => array('className' => 'Document'), + 'Extra1' => array('className' => 'Document'), + 'Extra2' => array('className' => 'Document')); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Device' => array('order' => array('Device.id' => 'ASC'))); } /** @@ -1714,13 +1675,12 @@ class DeviceType extends CakeTestModel { */ class DeviceTypeCategory extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'DeviceTypeCategory'; - +/** + * name property + * + * @var string + */ + public $name = 'DeviceTypeCategory'; } /** @@ -1730,13 +1690,12 @@ class DeviceTypeCategory extends CakeTestModel { */ class FeatureSet extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'FeatureSet'; - +/** + * name property + * + * @var string + */ + public $name = 'FeatureSet'; } /** @@ -1746,20 +1705,19 @@ class FeatureSet extends CakeTestModel { */ class ExteriorTypeCategory extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ExteriorTypeCategory'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Image' => array('className' => 'Device')); +/** + * name property + * + * @var string + */ + public $name = 'ExteriorTypeCategory'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Image' => array('className' => 'Device')); } /** @@ -1769,20 +1727,19 @@ class ExteriorTypeCategory extends CakeTestModel { */ class Document extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Document'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('DocumentDirectory'); +/** + * name property + * + * @var string + */ + public $name = 'Document'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('DocumentDirectory'); } /** @@ -1792,13 +1749,12 @@ class Document extends CakeTestModel { */ class Device extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Device'; - +/** + * name property + * + * @var string + */ + public $name = 'Device'; } /** @@ -1808,13 +1764,12 @@ class Device extends CakeTestModel { */ class DocumentDirectory extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'DocumentDirectory'; - +/** + * name property + * + * @var string + */ + public $name = 'DocumentDirectory'; } /** @@ -1824,13 +1779,12 @@ class DocumentDirectory extends CakeTestModel { */ class PrimaryModel extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'PrimaryModel'; - +/** + * name property + * + * @var string + */ + public $name = 'PrimaryModel'; } /** @@ -1840,13 +1794,12 @@ class PrimaryModel extends CakeTestModel { */ class SecondaryModel extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'SecondaryModel'; - +/** + * name property + * + * @var string + */ + public $name = 'SecondaryModel'; } /** @@ -1856,20 +1809,19 @@ class SecondaryModel extends CakeTestModel { */ class JoinA extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'JoinA'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('JoinB', 'JoinC'); +/** + * name property + * + * @var string + */ + public $name = 'JoinA'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('JoinB', 'JoinC'); } /** @@ -1879,20 +1831,19 @@ class JoinA extends CakeTestModel { */ class JoinB extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'JoinB'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('JoinA'); +/** + * name property + * + * @var string + */ + public $name = 'JoinB'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('JoinA'); } /** @@ -1902,20 +1853,19 @@ class JoinB extends CakeTestModel { */ class JoinC extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'JoinC'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('JoinA'); +/** + * name property + * + * @var string + */ + public $name = 'JoinC'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('JoinA'); } /** @@ -1925,34 +1875,33 @@ class JoinC extends CakeTestModel { */ class ThePaper extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ThePaper'; +/** + * name property + * + * @var string + */ + public $name = 'ThePaper'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'apples'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'apples'; - /** - * hasOne property - * - * @var array - */ - public $hasOne = array('Itself' => array('className' => 'ThePaper', 'foreignKey' => 'apple_id')); - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Monkey' => array('joinTable' => 'the_paper_monkies', 'order' => 'id')); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array('Itself' => array('className' => 'ThePaper', 'foreignKey' => 'apple_id')); +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Monkey' => array('joinTable' => 'the_paper_monkies', 'order' => 'id')); } /** @@ -1962,20 +1911,19 @@ class ThePaper extends CakeTestModel { */ class Monkey extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Monkey'; - - /** - * useTable property - * - * @var string - */ - public $useTable = 'devices'; +/** + * name property + * + * @var string + */ + public $name = 'Monkey'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'devices'; } /** @@ -1985,29 +1933,28 @@ class Monkey extends CakeTestModel { */ class AssociationTest1 extends CakeTestModel { - /** - * useTable property - * - * @var string - */ - public $useTable = 'join_as'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'join_as'; - /** - * name property - * - * @var string - */ - public $name = 'AssociationTest1'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('AssociationTest2' => array( - 'unique' => false, 'joinTable' => 'join_as_join_bs', 'foreignKey' => false - )); +/** + * name property + * + * @var string + */ + public $name = 'AssociationTest1'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('AssociationTest2' => array( + 'unique' => false, 'joinTable' => 'join_as_join_bs', 'foreignKey' => false + )); } /** @@ -2017,29 +1964,28 @@ class AssociationTest1 extends CakeTestModel { */ class AssociationTest2 extends CakeTestModel { - /** - * useTable property - * - * @var string - */ - public $useTable = 'join_bs'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'join_bs'; - /** - * name property - * - * @var string - */ - public $name = 'AssociationTest2'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('AssociationTest1' => array( - 'unique' => false, 'joinTable' => 'join_as_join_bs' - )); +/** + * name property + * + * @var string + */ + public $name = 'AssociationTest2'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('AssociationTest1' => array( + 'unique' => false, 'joinTable' => 'join_as_join_bs' + )); } /** @@ -2048,7 +1994,7 @@ class AssociationTest2 extends CakeTestModel { * @package Cake.Test.Case.Model */ class Callback extends CakeTestModel { - + } /** @@ -2058,55 +2004,55 @@ class Callback extends CakeTestModel { */ class CallbackPostTestModel extends CakeTestModel { - public $useTable = 'posts'; + public $useTable = 'posts'; - /** - * variable to control return of beforeValidate - * - * @var boolean - */ - public $beforeValidateReturn = true; +/** + * variable to control return of beforeValidate + * + * @var boolean + */ + public $beforeValidateReturn = true; - /** - * variable to control return of beforeSave - * - * @var boolean - */ - public $beforeSaveReturn = true; +/** + * variable to control return of beforeSave + * + * @var boolean + */ + public $beforeSaveReturn = true; - /** - * variable to control return of beforeDelete - * - * @var boolean - */ - public $beforeDeleteReturn = true; +/** + * variable to control return of beforeDelete + * + * @var boolean + */ + public $beforeDeleteReturn = true; - /** - * beforeSave callback - * - * @return boolean - */ - public function beforeSave($options = array()) { - return $this->beforeSaveReturn; - } +/** + * beforeSave callback + * + * @return boolean + */ + public function beforeSave($options = array()) { + return $this->beforeSaveReturn; + } - /** - * beforeValidate callback - * - * @return boolean - */ - public function beforeValidate($options = array()) { - return $this->beforeValidateReturn; - } +/** + * beforeValidate callback + * + * @return boolean + */ + public function beforeValidate($options = array()) { + return $this->beforeValidateReturn; + } - /** - * beforeDelete callback - * - * @return boolean - */ - public function beforeDelete($cascade = true) { - return $this->beforeDeleteReturn; - } +/** + * beforeDelete callback + * + * @return boolean + */ + public function beforeDelete($cascade = true) { + return $this->beforeDeleteReturn; + } } @@ -2117,13 +2063,12 @@ class CallbackPostTestModel extends CakeTestModel { */ class Uuid extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Uuid'; - +/** + * name property + * + * @var string + */ + public $name = 'Uuid'; } /** @@ -2133,13 +2078,12 @@ class Uuid extends CakeTestModel { */ class DataTest extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'DataTest'; - +/** + * name property + * + * @var string + */ + public $name = 'DataTest'; } /** @@ -2149,20 +2093,19 @@ class DataTest extends CakeTestModel { */ class TheVoid extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TheVoid'; - - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * name property + * + * @var string + */ + public $name = 'TheVoid'; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; } /** @@ -2172,82 +2115,82 @@ class TheVoid extends CakeTestModel { */ class ValidationTest1 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ValidationTest1'; +/** + * name property + * + * @var string + */ + public $name = 'ValidationTest1'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * schema property - * - * @var array - */ - protected $_schema = array(); +/** + * schema property + * + * @var array + */ + protected $_schema = array(); - /** - * validate property - * - * @var array - */ - public $validate = array( - 'title' => 'notEmpty', - 'published' => 'customValidationMethod', - 'body' => array( - 'notEmpty', - '/^.{5,}$/s' => 'no matchy', - '/^[0-9A-Za-z \\.]{1,}$/s' - ) - ); +/** + * validate property + * + * @var array + */ + public $validate = array( + 'title' => 'notEmpty', + 'published' => 'customValidationMethod', + 'body' => array( + 'notEmpty', + '/^.{5,}$/s' => 'no matchy', + '/^[0-9A-Za-z \\.]{1,}$/s' + ) + ); - /** - * customValidationMethod method - * - * @param mixed $data - * @return void - */ - public function customValidationMethod($data) { - return $data === 1; - } +/** + * customValidationMethod method + * + * @param mixed $data + * @return void + */ + public function customValidationMethod($data) { + return $data === 1; + } - /** - * Custom validator with parameters + default values - * - * @return array - */ - public function customValidatorWithParams($data, $validator, $or = true, $ignoreOnSame = 'id') { - $this->validatorParams = get_defined_vars(); - unset($this->validatorParams['this']); - return true; - } +/** + * Custom validator with parameters + default values + * + * @return array + */ + public function customValidatorWithParams($data, $validator, $or = true, $ignoreOnSame = 'id') { + $this->validatorParams = get_defined_vars(); + unset($this->validatorParams['this']); + return true; + } - /** - * Custom validator with message - * - * @return array - */ - public function customValidatorWithMessage($data) { - return 'This field will *never* validate! Muhahaha!'; - } +/** + * Custom validator with message + * + * @return array + */ + public function customValidatorWithMessage($data) { + return 'This field will *never* validate! Muhahaha!'; + } - /** - * Test validation with many parameters - * - * @return void - */ - public function customValidatorWithSixParams($data, $one = 1, $two = 2, $three = 3, $four = 4, $five = 5, $six = 6) { - $this->validatorParams = get_defined_vars(); - unset($this->validatorParams['this']); - return true; - } +/** + * Test validation with many parameters + * + * @return void + */ + public function customValidatorWithSixParams($data, $one = 1, $two = 2, $three = 3, $four = 4, $five = 5, $six = 6) { + $this->validatorParams = get_defined_vars(); + unset($this->validatorParams['this']); + return true; + } } @@ -2258,53 +2201,53 @@ class ValidationTest1 extends CakeTestModel { */ class ValidationTest2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ValidationTest2'; +/** + * name property + * + * @var string + */ + public $name = 'ValidationTest2'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * validate property - * - * @var array - */ - public $validate = array( - 'title' => 'notEmpty', - 'published' => 'customValidationMethod', - 'body' => array( - 'notEmpty', - '/^.{5,}$/s' => 'no matchy', - '/^[0-9A-Za-z \\.]{1,}$/s' - ) - ); +/** + * validate property + * + * @var array + */ + public $validate = array( + 'title' => 'notEmpty', + 'published' => 'customValidationMethod', + 'body' => array( + 'notEmpty', + '/^.{5,}$/s' => 'no matchy', + '/^[0-9A-Za-z \\.]{1,}$/s' + ) + ); - /** - * customValidationMethod method - * - * @param mixed $data - * @return void - */ - public function customValidationMethod($data) { - return $data === 1; - } +/** + * customValidationMethod method + * + * @param mixed $data + * @return void + */ + public function customValidationMethod($data) { + return $data === 1; + } - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - return array(); - } +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + return array(); + } } @@ -2315,29 +2258,28 @@ class ValidationTest2 extends CakeTestModel { */ class Person extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Person'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Mother' => array( - 'className' => 'Person', - 'foreignKey' => 'mother_id' - ), - 'Father' => array( - 'className' => 'Person', - 'foreignKey' => 'father_id' - ) - ); +/** + * name property + * + * @var string + */ + public $name = 'Person'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Mother' => array( + 'className' => 'Person', + 'foreignKey' => 'mother_id' + ), + 'Father' => array( + 'className' => 'Person', + 'foreignKey' => 'father_id' + ) + ); } /** @@ -2347,13 +2289,12 @@ class Person extends CakeTestModel { */ class UnderscoreField extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'UnderscoreField'; - +/** + * name property + * + * @var string + */ + public $name = 'UnderscoreField'; } /** @@ -2363,13 +2304,12 @@ class UnderscoreField extends CakeTestModel { */ class Product extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Product'; - +/** + * name property + * + * @var string + */ + public $name = 'Product'; } /** @@ -2379,34 +2319,33 @@ class Product extends CakeTestModel { */ class Story extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Story'; +/** + * name property + * + * @var string + */ + public $name = 'Story'; - /** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'story'; +/** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'story'; - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Tag' => array('foreignKey' => 'story')); - - /** - * validate property - * - * @var array - */ - public $validate = array('title' => 'notEmpty'); +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Tag' => array('foreignKey' => 'story')); +/** + * validate property + * + * @var array + */ + public $validate = array('title' => 'notEmpty'); } /** @@ -2416,25 +2355,25 @@ class Story extends CakeTestModel { */ class Cd extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Cd'; +/** + * name property + * + * @var string + */ + public $name = 'Cd'; - /** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'OverallFavorite' => array( - 'foreignKey' => 'model_id', - 'dependent' => true, - 'conditions' => array('model_type' => 'Cd') - ) - ); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'OverallFavorite' => array( + 'foreignKey' => 'model_id', + 'dependent' => true, + 'conditions' => array('model_type' => 'Cd') + ) + ); } @@ -2445,25 +2384,25 @@ class Cd extends CakeTestModel { */ class Book extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Book'; +/** + * name property + * + * @var string + */ + public $name = 'Book'; - /** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'OverallFavorite' => array( - 'foreignKey' => 'model_id', - 'dependent' => true, - 'conditions' => 'OverallFavorite.model_type = \'Book\'' - ) - ); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'OverallFavorite' => array( + 'foreignKey' => 'model_id', + 'dependent' => true, + 'conditions' => 'OverallFavorite.model_type = \'Book\'' + ) + ); } @@ -2474,13 +2413,12 @@ class Book extends CakeTestModel { */ class OverallFavorite extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'OverallFavorite'; - +/** + * name property + * + * @var string + */ + public $name = 'OverallFavorite'; } /** @@ -2490,20 +2428,19 @@ class OverallFavorite extends CakeTestModel { */ class MyUser extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'MyUser'; - - /** - * undocumented variable - * - * @var string - */ - public $hasAndBelongsToMany = array('MyCategory'); +/** + * name property + * + * @var string + */ + public $name = 'MyUser'; +/** + * undocumented variable + * + * @var string + */ + public $hasAndBelongsToMany = array('MyCategory'); } /** @@ -2513,20 +2450,19 @@ class MyUser extends CakeTestModel { */ class MyCategory extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'MyCategory'; - - /** - * undocumented variable - * - * @var string - */ - public $hasAndBelongsToMany = array('MyProduct', 'MyUser'); +/** + * name property + * + * @var string + */ + public $name = 'MyCategory'; +/** + * undocumented variable + * + * @var string + */ + public $hasAndBelongsToMany = array('MyProduct', 'MyUser'); } /** @@ -2536,20 +2472,19 @@ class MyCategory extends CakeTestModel { */ class MyProduct extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'MyProduct'; - - /** - * undocumented variable - * - * @var string - */ - public $hasAndBelongsToMany = array('MyCategory'); +/** + * name property + * + * @var string + */ + public $name = 'MyProduct'; +/** + * undocumented variable + * + * @var string + */ + public $hasAndBelongsToMany = array('MyCategory'); } /** @@ -2559,13 +2494,12 @@ class MyProduct extends CakeTestModel { */ class MyCategoriesMyUser extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'MyCategoriesMyUser'; - +/** + * name property + * + * @var string + */ + public $name = 'MyCategoriesMyUser'; } /** @@ -2575,15 +2509,15 @@ class MyCategoriesMyUser extends CakeTestModel { */ class MyCategoriesMyProduct extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'MyCategoriesMyProduct'; - +/** + * name property + * + * @var string + */ + public $name = 'MyCategoriesMyProduct'; } + /** * NumberTree class * @@ -2591,60 +2525,60 @@ class MyCategoriesMyProduct extends CakeTestModel { */ class NumberTree extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'NumberTree'; +/** + * name property + * + * @var string + */ + public $name = 'NumberTree'; - /** - * actsAs property - * - * @var array - */ - public $actsAs = array('Tree'); +/** + * actsAs property + * + * @var array + */ + public $actsAs = array('Tree'); - /** - * initialize method - * - * @param integer $levelLimit - * @param integer $childLimit - * @param mixed $currentLevel - * @param mixed $parent_id - * @param string $prefix - * @param boolean $hierarchal - * @return void - */ - public function initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parentId = null, $prefix = '1', $hierarchal = true) { - if (!$parentId) { - $db = ConnectionManager::getDataSource($this->useDbConfig); - $db->truncate($this->table); - $this->save(array($this->name => array('name' => '1. Root'))); - $this->initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierarchal); - $this->create(array()); - } - - if (!$currentLevel || $currentLevel > $levelLimit) { - return; - } - - for ($i = 1; $i <= $childLimit; $i++) { - $name = $prefix . '.' . $i; - $data = array($this->name => array('name' => $name)); - $this->create($data); - - if ($hierarchal) { - if ($this->name === 'UnconventionalTree') { - $data[$this->name]['join'] = $parentId; - } else { - $data[$this->name]['parent_id'] = $parentId; +/** + * initialize method + * + * @param integer $levelLimit + * @param integer $childLimit + * @param mixed $currentLevel + * @param mixed $parent_id + * @param string $prefix + * @param boolean $hierarchal + * @return void + */ + public function initialize($levelLimit = 3, $childLimit = 3, $currentLevel = null, $parentId = null, $prefix = '1', $hierarchal = true) { + if (!$parentId) { + $db = ConnectionManager::getDataSource($this->useDbConfig); + $db->truncate($this->table); + $this->save(array($this->name => array('name' => '1. Root'))); + $this->initialize($levelLimit, $childLimit, 1, $this->id, '1', $hierarchal); + $this->create(array()); + } + + if (!$currentLevel || $currentLevel > $levelLimit) { + return; + } + + for ($i = 1; $i <= $childLimit; $i++) { + $name = $prefix . '.' . $i; + $data = array($this->name => array('name' => $name)); + $this->create($data); + + if ($hierarchal) { + if ($this->name === 'UnconventionalTree') { + $data[$this->name]['join'] = $parentId; + } else { + $data[$this->name]['parent_id'] = $parentId; + } + } + $this->save($data); + $this->initialize($levelLimit, $childLimit, $currentLevel + 1, $this->id, $name, $hierarchal); } - } - $this->save($data); - $this->initialize($levelLimit, $childLimit, $currentLevel + 1, $this->id, $name, $hierarchal); } - } } @@ -2655,20 +2589,19 @@ class NumberTree extends CakeTestModel { */ class NumberTreeTwo extends NumberTree { - /** - * name property - * - * @var string - */ - public $name = 'NumberTreeTwo'; - - /** - * actsAs property - * - * @var array - */ - public $actsAs = array(); +/** + * name property + * + * @var string + */ + public $name = 'NumberTreeTwo'; +/** + * actsAs property + * + * @var array + */ + public $actsAs = array(); } /** @@ -2678,13 +2611,12 @@ class NumberTreeTwo extends NumberTree { */ class FlagTree extends NumberTree { - /** - * name property - * - * @var string - */ - public $name = 'FlagTree'; - +/** + * name property + * + * @var string + */ + public $name = 'FlagTree'; } /** @@ -2694,19 +2626,20 @@ class FlagTree extends NumberTree { */ class UnconventionalTree extends NumberTree { - /** - * name property - * - * @var string - */ - public $name = 'UnconventionalTree'; - public $actsAs = array( - 'Tree' => array( - 'parent' => 'join', - 'left' => 'left', - 'right' => 'right' - ) - ); +/** + * name property + * + * @var string + */ + public $name = 'UnconventionalTree'; + + public $actsAs = array( + 'Tree' => array( + 'parent' => 'join', + 'left' => 'left', + 'right' => 'right' + ) + ); } @@ -2717,13 +2650,12 @@ class UnconventionalTree extends NumberTree { */ class UuidTree extends NumberTree { - /** - * name property - * - * @var string - */ - public $name = 'UuidTree'; - +/** + * name property + * + * @var string + */ + public $name = 'UuidTree'; } /** @@ -2733,20 +2665,19 @@ class UuidTree extends NumberTree { */ class Campaign extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Campaign'; - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Ad' => array('fields' => array('id', 'campaign_id', 'name'))); +/** + * name property + * + * @var string + */ + public $name = 'Campaign'; +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Ad' => array('fields' => array('id', 'campaign_id', 'name'))); } /** @@ -2756,27 +2687,26 @@ class Campaign extends CakeTestModel { */ class Ad extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Ad'; +/** + * name property + * + * @var string + */ + public $name = 'Ad'; - /** - * actsAs property - * - * @var array - */ - public $actsAs = array('Tree'); - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Campaign'); +/** + * actsAs property + * + * @var array + */ + public $actsAs = array('Tree'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Campaign'); } /** @@ -2786,25 +2716,25 @@ class Ad extends CakeTestModel { */ class AfterTree extends NumberTree { - /** - * name property - * - * @var string - */ - public $name = 'AfterTree'; +/** + * name property + * + * @var string + */ + public $name = 'AfterTree'; - /** - * actsAs property - * - * @var array - */ - public $actsAs = array('Tree'); +/** + * actsAs property + * + * @var array + */ + public $actsAs = array('Tree'); - public function afterSave($created) { - if ($created && isset($this->data['AfterTree'])) { - $this->data['AfterTree']['name'] = 'Six and One Half Changed in AfterTree::afterSave() but not in database'; + public function afterSave($created) { + if ($created && isset($this->data['AfterTree'])) { + $this->data['AfterTree']['name'] = 'Six and One Half Changed in AfterTree::afterSave() but not in database'; + } } - } } @@ -2815,34 +2745,33 @@ class AfterTree extends NumberTree { */ class Content extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Content'; +/** + * name property + * + * @var string + */ + public $name = 'Content'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'Content'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'Content'; - /** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'iContentId'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Account' => array('className' => 'Account', 'with' => 'ContentAccount', 'joinTable' => 'ContentAccounts', 'foreignKey' => 'iContentId', 'associationForeignKey', 'iAccountId')); +/** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'iContentId'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Account' => array('className' => 'Account', 'with' => 'ContentAccount', 'joinTable' => 'ContentAccounts', 'foreignKey' => 'iContentId', 'associationForeignKey', 'iAccountId')); } /** @@ -2852,27 +2781,26 @@ class Content extends CakeTestModel { */ class Account extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Account'; +/** + * name property + * + * @var string + */ + public $name = 'Account'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'Accounts'; - - /** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'iAccountId'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'Accounts'; +/** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'iAccountId'; } /** @@ -2882,27 +2810,26 @@ class Account extends CakeTestModel { */ class ContentAccount extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ContentAccount'; +/** + * name property + * + * @var string + */ + public $name = 'ContentAccount'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'ContentAccounts'; - - /** - * primaryKey property - * - * @var string - */ - public $primaryKey = 'iContentAccountsId'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'ContentAccounts'; +/** + * primaryKey property + * + * @var string + */ + public $primaryKey = 'iContentAccountsId'; } /** @@ -2912,7 +2839,7 @@ class ContentAccount extends CakeTestModel { */ class FilmFile extends CakeTestModel { - public $name = 'FilmFile'; + public $name = 'FilmFile'; } @@ -2923,16 +2850,17 @@ class FilmFile extends CakeTestModel { */ class Basket extends CakeTestModel { - public $name = 'Basket'; - public $belongsTo = array( - 'FilmFile' => array( - 'className' => 'FilmFile', - 'foreignKey' => 'object_id', - 'conditions' => "Basket.type = 'file'", - 'fields' => '', - 'order' => '' - ) - ); + public $name = 'Basket'; + + public $belongsTo = array( + 'FilmFile' => array( + 'className' => 'FilmFile', + 'foreignKey' => 'object_id', + 'conditions' => "Basket.type = 'file'", + 'fields' => '', + 'order' => '' + ) + ); } @@ -2943,33 +2871,32 @@ class Basket extends CakeTestModel { */ class TestPluginArticle extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestPluginArticle'; +/** + * name property + * + * @var string + */ + public $name = 'TestPluginArticle'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'TestPluginComment' => array( - 'className' => 'TestPlugin.TestPluginComment', - 'foreignKey' => 'article_id', - 'dependent' => true - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'TestPluginComment' => array( + 'className' => 'TestPlugin.TestPluginComment', + 'foreignKey' => 'article_id', + 'dependent' => true + ) + ); } /** @@ -2979,26 +2906,25 @@ class TestPluginArticle extends CakeTestModel { */ class TestPluginComment extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestPluginComment'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestPluginArticle' => array( - 'className' => 'TestPlugin.TestPluginArticle', - 'foreignKey' => 'article_id', - ), - 'TestPlugin.User' - ); +/** + * name property + * + * @var string + */ + public $name = 'TestPluginComment'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestPluginArticle' => array( + 'className' => 'TestPlugin.TestPluginArticle', + 'foreignKey' => 'article_id', + ), + 'TestPlugin.User' + ); } /** @@ -3008,20 +2934,19 @@ class TestPluginComment extends CakeTestModel { */ class Uuidportfolio extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Uuidportfolio'; - - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Uuiditem'); +/** + * name property + * + * @var string + */ + public $name = 'Uuidportfolio'; +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Uuiditem'); } /** @@ -3031,19 +2956,19 @@ class Uuidportfolio extends CakeTestModel { */ class Uuiditem extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Uuiditem'; +/** + * name property + * + * @var string + */ + public $name = 'Uuiditem'; - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolioNumericid')); +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('Uuidportfolio' => array('with' => 'UuiditemsUuidportfolioNumericid')); } @@ -3054,13 +2979,12 @@ class Uuiditem extends CakeTestModel { */ class UuiditemsUuidportfolio extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'UuiditemsUuidportfolio'; - +/** + * name property + * + * @var string + */ + public $name = 'UuiditemsUuidportfolio'; } /** @@ -3070,13 +2994,12 @@ class UuiditemsUuidportfolio extends CakeTestModel { */ class UuiditemsUuidportfolioNumericid extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'UuiditemsUuidportfolioNumericid'; - +/** + * name property + * + * @var string + */ + public $name = 'UuiditemsUuidportfolioNumericid'; } /** @@ -3086,27 +3009,26 @@ class UuiditemsUuidportfolioNumericid extends CakeTestModel { */ class TranslateTestModel extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TranslateTestModel'; +/** + * name property + * + * @var string + */ + public $name = 'TranslateTestModel'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'i18n'; - - /** - * displayField property - * - * @var string - */ - public $displayField = 'field'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'i18n'; +/** + * displayField property + * + * @var string + */ + public $displayField = 'field'; } /** @@ -3116,26 +3038,26 @@ class TranslateTestModel extends CakeTestModel { */ class TranslateWithPrefix extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TranslateWithPrefix'; +/** + * name property + * + * @var string + */ + public $name = 'TranslateWithPrefix'; - /** - * tablePrefix property - * - * @var string - */ - public $tablePrefix = 'i18n_'; +/** + * tablePrefix property + * + * @var string + */ + public $tablePrefix = 'i18n_'; - /** - * displayField property - * - * @var string - */ - public $displayField = 'field'; +/** + * displayField property + * + * @var string + */ + public $displayField = 'field'; } @@ -3146,33 +3068,33 @@ class TranslateWithPrefix extends CakeTestModel { */ class TranslatedItem extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TranslatedItem'; +/** + * name property + * + * @var string + */ + public $name = 'TranslatedItem'; - /** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; +/** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; - /** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('content', 'title')); +/** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('content', 'title')); - /** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateTestModel'; +/** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateTestModel'; } @@ -3183,33 +3105,33 @@ class TranslatedItem extends CakeTestModel { */ class TranslatedItem2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TranslatedItem'; +/** + * name property + * + * @var string + */ + public $name = 'TranslatedItem'; - /** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; +/** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; - /** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('content', 'title')); +/** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('content', 'title')); - /** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateWithPrefix'; +/** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateWithPrefix'; } @@ -3220,47 +3142,47 @@ class TranslatedItem2 extends CakeTestModel { */ class TranslatedItemWithTable extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TranslatedItemWithTable'; +/** + * name property + * + * @var string + */ + public $name = 'TranslatedItemWithTable'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'translated_items'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'translated_items'; - /** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; +/** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; - /** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('content', 'title')); +/** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('content', 'title')); - /** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateTestModel'; +/** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateTestModel'; - /** - * translateTable property - * - * @var string - */ - public $translateTable = 'another_i18n'; +/** + * translateTable property + * + * @var string + */ + public $translateTable = 'another_i18n'; } @@ -3271,26 +3193,26 @@ class TranslatedItemWithTable extends CakeTestModel { */ class TranslateArticleModel extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TranslateArticleModel'; +/** + * name property + * + * @var string + */ + public $name = 'TranslateArticleModel'; - /** - * useTable property - * - * @var string - */ - public $useTable = 'article_i18n'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'article_i18n'; - /** - * displayField property - * - * @var string - */ - public $displayField = 'field'; +/** + * displayField property + * + * @var string + */ + public $displayField = 'field'; } @@ -3301,273 +3223,299 @@ class TranslateArticleModel extends CakeTestModel { */ class TranslatedArticle extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TranslatedArticle'; +/** + * name property + * + * @var string + */ + public $name = 'TranslatedArticle'; - /** - * cacheQueries property - * - * @var bool false - */ - public $cacheQueries = false; +/** + * cacheQueries property + * + * @var bool false + */ + public $cacheQueries = false; - /** - * actsAs property - * - * @var array - */ - public $actsAs = array('Translate' => array('title', 'body')); +/** + * actsAs property + * + * @var array + */ + public $actsAs = array('Translate' => array('title', 'body')); - /** - * translateModel property - * - * @var string - */ - public $translateModel = 'TranslateArticleModel'; +/** + * translateModel property + * + * @var string + */ + public $translateModel = 'TranslateArticleModel'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); - /** - * belongsTo property - * - * @var array - */ - public $hasMany = array('TranslatedItem'); +/** + * belongsTo property + * + * @var array + */ + public $hasMany = array('TranslatedItem'); } class CounterCacheUser extends CakeTestModel { - public $name = 'CounterCacheUser'; - public $alias = 'User'; - public $hasMany = array( - 'Post' => array( - 'className' => 'CounterCachePost', - 'foreignKey' => 'user_id' - ) - ); + public $name = 'CounterCacheUser'; + public $alias = 'User'; + + public $hasMany = array( + 'Post' => array( + 'className' => 'CounterCachePost', + 'foreignKey' => 'user_id' + ) + ); } class CounterCachePost extends CakeTestModel { - public $name = 'CounterCachePost'; - public $alias = 'Post'; - public $belongsTo = array( - 'User' => array( - 'className' => 'CounterCacheUser', - 'foreignKey' => 'user_id', - 'counterCache' => true - ) - ); + public $name = 'CounterCachePost'; + public $alias = 'Post'; + + public $belongsTo = array( + 'User' => array( + 'className' => 'CounterCacheUser', + 'foreignKey' => 'user_id', + 'counterCache' => true + ) + ); } class CounterCacheUserNonstandardPrimaryKey extends CakeTestModel { - public $name = 'CounterCacheUserNonstandardPrimaryKey'; - public $alias = 'User'; - public $primaryKey = 'uid'; - public $hasMany = array( - 'Post' => array( - 'className' => 'CounterCachePostNonstandardPrimaryKey', - 'foreignKey' => 'uid' - ) - ); + public $name = 'CounterCacheUserNonstandardPrimaryKey'; + + public $alias = 'User'; + + public $primaryKey = 'uid'; + + public $hasMany = array( + 'Post' => array( + 'className' => 'CounterCachePostNonstandardPrimaryKey', + 'foreignKey' => 'uid' + ) + ); } class CounterCachePostNonstandardPrimaryKey extends CakeTestModel { - public $name = 'CounterCachePostNonstandardPrimaryKey'; - public $alias = 'Post'; - public $primaryKey = 'pid'; - public $belongsTo = array( - 'User' => array( - 'className' => 'CounterCacheUserNonstandardPrimaryKey', - 'foreignKey' => 'uid', - 'counterCache' => true - ) - ); + public $name = 'CounterCachePostNonstandardPrimaryKey'; + + public $alias = 'Post'; + + public $primaryKey = 'pid'; + + public $belongsTo = array( + 'User' => array( + 'className' => 'CounterCacheUserNonstandardPrimaryKey', + 'foreignKey' => 'uid', + 'counterCache' => true + ) + ); } class ArticleB extends CakeTestModel { - public $name = 'ArticleB'; - public $useTable = 'articles'; - public $hasAndBelongsToMany = array( - 'TagB' => array( - 'className' => 'TagB', - 'joinTable' => 'articles_tags', - 'foreignKey' => 'article_id', - 'associationForeignKey' => 'tag_id' - ) - ); + public $name = 'ArticleB'; + + public $useTable = 'articles'; + + public $hasAndBelongsToMany = array( + 'TagB' => array( + 'className' => 'TagB', + 'joinTable' => 'articles_tags', + 'foreignKey' => 'article_id', + 'associationForeignKey' => 'tag_id' + ) + ); } class TagB extends CakeTestModel { - public $name = 'TagB'; - public $useTable = 'tags'; - public $hasAndBelongsToMany = array( - 'ArticleB' => array( - 'className' => 'ArticleB', - 'joinTable' => 'articles_tags', - 'foreignKey' => 'tag_id', - 'associationForeignKey' => 'article_id' - ) - ); + public $name = 'TagB'; + + public $useTable = 'tags'; + + public $hasAndBelongsToMany = array( + 'ArticleB' => array( + 'className' => 'ArticleB', + 'joinTable' => 'articles_tags', + 'foreignKey' => 'tag_id', + 'associationForeignKey' => 'article_id' + ) + ); } class Fruit extends CakeTestModel { - public $name = 'Fruit'; - public $hasAndBelongsToMany = array( - 'UuidTag' => array( - 'className' => 'UuidTag', - 'joinTable' => 'fruits_uuid_tags', - 'foreignKey' => 'fruit_id', - 'associationForeignKey' => 'uuid_tag_id', - 'with' => 'FruitsUuidTag' - ) - ); + public $name = 'Fruit'; + + public $hasAndBelongsToMany = array( + 'UuidTag' => array( + 'className' => 'UuidTag', + 'joinTable' => 'fruits_uuid_tags', + 'foreignKey' => 'fruit_id', + 'associationForeignKey' => 'uuid_tag_id', + 'with' => 'FruitsUuidTag' + ) + ); } class FruitsUuidTag extends CakeTestModel { - public $name = 'FruitsUuidTag'; - public $primaryKey = false; - public $belongsTo = array( - 'UuidTag' => array( - 'className' => 'UuidTag', - 'foreignKey' => 'uuid_tag_id', - ), - 'Fruit' => array( - 'className' => 'Fruit', - 'foreignKey' => 'fruit_id', - ) - ); + public $name = 'FruitsUuidTag'; + + public $primaryKey = false; + + public $belongsTo = array( + 'UuidTag' => array( + 'className' => 'UuidTag', + 'foreignKey' => 'uuid_tag_id', + ), + 'Fruit' => array( + 'className' => 'Fruit', + 'foreignKey' => 'fruit_id', + ) + ); } class UuidTag extends CakeTestModel { - public $name = 'UuidTag'; - public $hasAndBelongsToMany = array( - 'Fruit' => array( - 'className' => 'Fruit', - 'joinTable' => 'fruits_uuid_tags', - 'foreign_key' => 'uuid_tag_id', - 'associationForeignKey' => 'fruit_id', - 'with' => 'FruitsUuidTag' - ) - ); + public $name = 'UuidTag'; + + public $hasAndBelongsToMany = array( + 'Fruit' => array( + 'className' => 'Fruit', + 'joinTable' => 'fruits_uuid_tags', + 'foreign_key' => 'uuid_tag_id', + 'associationForeignKey' => 'fruit_id', + 'with' => 'FruitsUuidTag' + ) + ); } class FruitNoWith extends CakeTestModel { - public $name = 'Fruit'; - public $useTable = 'fruits'; - public $hasAndBelongsToMany = array( - 'UuidTag' => array( - 'className' => 'UuidTagNoWith', - 'joinTable' => 'fruits_uuid_tags', - 'foreignKey' => 'fruit_id', - 'associationForeignKey' => 'uuid_tag_id', - ) - ); + public $name = 'Fruit'; + + public $useTable = 'fruits'; + + public $hasAndBelongsToMany = array( + 'UuidTag' => array( + 'className' => 'UuidTagNoWith', + 'joinTable' => 'fruits_uuid_tags', + 'foreignKey' => 'fruit_id', + 'associationForeignKey' => 'uuid_tag_id', + ) + ); } class UuidTagNoWith extends CakeTestModel { - public $name = 'UuidTag'; - public $useTable = 'uuid_tags'; - public $hasAndBelongsToMany = array( - 'Fruit' => array( - 'className' => 'FruitNoWith', - 'joinTable' => 'fruits_uuid_tags', - 'foreign_key' => 'uuid_tag_id', - 'associationForeignKey' => 'fruit_id', - ) - ); + public $name = 'UuidTag'; + + public $useTable = 'uuid_tags'; + + public $hasAndBelongsToMany = array( + 'Fruit' => array( + 'className' => 'FruitNoWith', + 'joinTable' => 'fruits_uuid_tags', + 'foreign_key' => 'uuid_tag_id', + 'associationForeignKey' => 'fruit_id', + ) + ); } class ProductUpdateAll extends CakeTestModel { - public $name = 'ProductUpdateAll'; - public $useTable = 'product_update_all'; + public $name = 'ProductUpdateAll'; + + public $useTable = 'product_update_all'; } class GroupUpdateAll extends CakeTestModel { - public $name = 'GroupUpdateAll'; - public $useTable = 'group_update_all'; + public $name = 'GroupUpdateAll'; + + public $useTable = 'group_update_all'; } class TransactionTestModel extends CakeTestModel { - public $name = 'TransactionTestModel'; - public $useTable = 'samples'; + public $name = 'TransactionTestModel'; - public function afterSave($created) { - $data = array( - array('apple_id' => 1, 'name' => 'sample6'), - ); - $this->saveAll($data, array('atomic' => true, 'callbacks' => false)); - } + public $useTable = 'samples'; + + public function afterSave($created) { + $data = array( + array('apple_id' => 1, 'name' => 'sample6'), + ); + $this->saveAll($data, array('atomic' => true, 'callbacks' => false)); + } } class TransactionManyTestModel extends CakeTestModel { - public $name = 'TransactionManyTestModel'; - public $useTable = 'samples'; + public $name = 'TransactionManyTestModel'; - public function afterSave($created) { - $data = array( - array('apple_id' => 1, 'name' => 'sample6'), - ); - $this->saveMany($data, array('atomic' => true, 'callbacks' => false)); - } + public $useTable = 'samples'; + + public function afterSave($created) { + $data = array( + array('apple_id' => 1, 'name' => 'sample6'), + ); + $this->saveMany($data, array('atomic' => true, 'callbacks' => false)); + } } class Site extends CakeTestModel { - public $name = 'Site'; - public $useTable = 'sites'; - public $hasAndBelongsToMany = array( - 'Domain' => array('unique' => 'keepExisting'), - ); + public $name = 'Site'; + public $useTable = 'sites'; + + public $hasAndBelongsToMany = array( + 'Domain' => array('unique' => 'keepExisting'), + ); } class Domain extends CakeTestModel { - public $name = 'Domain'; - public $useTable = 'domains'; - public $hasAndBelongsToMany = array( - 'Site' => array('unique' => 'keepExisting'), - ); + public $name = 'Domain'; + public $useTable = 'domains'; + + public $hasAndBelongsToMany = array( + 'Site' => array('unique' => 'keepExisting'), + ); } /** @@ -3577,71 +3525,71 @@ class Domain extends CakeTestModel { */ class TestModel extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * schema property - * - * @var array - */ - protected $_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), - 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => '155'), - 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema property + * + * @var array + */ + protected $_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), + 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => '155'), + 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); - /** - * find method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function find($conditions = null, $fields = null, $order = null, $recursive = null) { - return array($conditions, $fields); - } +/** + * find method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function find($conditions = null, $fields = null, $order = null, $recursive = null) { + return array($conditions, $fields); + } - /** - * findAll method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } +/** + * findAll method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } } @@ -3652,20 +3600,19 @@ class TestModel extends CakeTestModel { */ class TestModel2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel2'; - - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * name property + * + * @var string + */ + public $name = 'TestModel2'; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; } /** @@ -3675,20 +3622,19 @@ class TestModel2 extends CakeTestModel { */ class TestModel3 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel3'; - - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * name property + * + * @var string + */ + public $name = 'TestModel3'; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; } /** @@ -3698,80 +3644,80 @@ class TestModel3 extends CakeTestModel { */ class TestModel4 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel4'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel4'; - /** - * table property - * - * @var string - */ - public $table = 'test_model4'; +/** + * table property + * + * @var string + */ + public $table = 'test_model4'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestModel4Parent' => array( - 'className' => 'TestModel4', - 'foreignKey' => 'parent_id' - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestModel4Parent' => array( + 'className' => 'TestModel4', + 'foreignKey' => 'parent_id' + ) + ); - /** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'TestModel5' => array( - 'className' => 'TestModel5', - 'foreignKey' => 'test_model4_id' - ) - ); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'TestModel5' => array( + 'className' => 'TestModel5', + 'foreignKey' => 'test_model4_id' + ) + ); - /** - * hasAndBelongsToMany property - * - * @var array - */ - public $hasAndBelongsToMany = array('TestModel7' => array( - 'className' => 'TestModel7', - 'joinTable' => 'test_model4_test_model7', - 'foreignKey' => 'test_model4_id', - 'associationForeignKey' => 'test_model7_id', - 'with' => 'TestModel4TestModel7' - )); +/** + * hasAndBelongsToMany property + * + * @var array + */ + public $hasAndBelongsToMany = array('TestModel7' => array( + 'className' => 'TestModel7', + 'joinTable' => 'test_model4_test_model7', + 'foreignKey' => 'test_model4_id', + 'associationForeignKey' => 'test_model7_id', + 'with' => 'TestModel4TestModel7' + )); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -3782,41 +3728,41 @@ class TestModel4 extends CakeTestModel { */ class TestModel4TestModel7 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel4TestModel7'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel4TestModel7'; - /** - * table property - * - * @var string - */ - public $table = 'test_model4_test_model7'; +/** + * table property + * + * @var string + */ + public $table = 'test_model4_test_model7'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8') - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8') + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -3827,64 +3773,64 @@ class TestModel4TestModel7 extends CakeTestModel { */ class TestModel5 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel5'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel5'; - /** - * table property - * - * @var string - */ - public $table = 'test_model5'; +/** + * table property + * + * @var string + */ + public $table = 'test_model5'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('TestModel4' => array( - 'className' => 'TestModel4', - 'foreignKey' => 'test_model4_id' - )); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('TestModel4' => array( + 'className' => 'TestModel4', + 'foreignKey' => 'test_model4_id' + )); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('TestModel6' => array( - 'className' => 'TestModel6', - 'foreignKey' => 'test_model5_id' - )); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('TestModel6' => array( + 'className' => 'TestModel6', + 'foreignKey' => 'test_model5_id' + )); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -3895,56 +3841,56 @@ class TestModel5 extends CakeTestModel { */ class TestModel6 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel6'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel6'; - /** - * table property - * - * @var string - */ - public $table = 'test_model6'; +/** + * table property + * + * @var string + */ + public $table = 'test_model6'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestModel5' => array( - 'className' => 'TestModel5', - 'foreignKey' => 'test_model5_id' - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestModel5' => array( + 'className' => 'TestModel5', + 'foreignKey' => 'test_model5_id' + ) + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model5_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model5_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -3955,43 +3901,43 @@ class TestModel6 extends CakeTestModel { */ class TestModel7 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel7'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel7'; - /** - * table property - * - * @var string - */ - public $table = 'test_model7'; +/** + * table property + * + * @var string + */ + public $table = 'test_model7'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4002,57 +3948,57 @@ class TestModel7 extends CakeTestModel { */ class TestModel8 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel8'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel8'; - /** - * table property - * - * @var string - */ - public $table = 'test_model8'; +/** + * table property + * + * @var string + */ + public $table = 'test_model8'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'TestModel9' => array( - 'className' => 'TestModel9', - 'foreignKey' => 'test_model8_id', - 'conditions' => 'TestModel9.name != \'mariano\'' - ) - ); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'TestModel9' => array( + 'className' => 'TestModel9', + 'foreignKey' => 'test_model8_id', + 'conditions' => 'TestModel9.name != \'mariano\'' + ) + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model9_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model9_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4063,57 +4009,57 @@ class TestModel8 extends CakeTestModel { */ class TestModel9 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'TestModel9'; +/** + * name property + * + * @var string + */ + public $name = 'TestModel9'; - /** - * table property - * - * @var string - */ - public $table = 'test_model9'; +/** + * table property + * + * @var string + */ + public $table = 'test_model9'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'TestModel8' => array( - 'className' => 'TestModel8', - 'foreignKey' => 'test_model8_id', - 'conditions' => 'TestModel8.name != \'larry\'' - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'TestModel8' => array( + 'className' => 'TestModel8', + 'foreignKey' => 'test_model8_id', + 'conditions' => 'TestModel8.name != \'larry\'' + ) + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'test_model8_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'test_model8_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4124,55 +4070,55 @@ class TestModel9 extends CakeTestModel { */ class Level extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Level'; +/** + * name property + * + * @var string + */ + public $name = 'Level'; - /** - * table property - * - * @var string - */ - public $table = 'level'; +/** + * table property + * + * @var string + */ + public $table = 'level'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Group' => array( - 'className' => 'Group' - ), - 'User2' => array( - 'className' => 'User2' - ) - ); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Group' => array( + 'className' => 'Group' + ), + 'User2' => array( + 'className' => 'User2' + ) + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4183,56 +4129,56 @@ class Level extends CakeTestModel { */ class Group extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Group'; +/** + * name property + * + * @var string + */ + public $name = 'Group'; - /** - * table property - * - * @var string - */ - public $table = 'group'; +/** + * table property + * + * @var string + */ + public $table = 'group'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('Level'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('Level'); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array('Category2', 'User2'); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array('Category2', 'User2'); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4243,68 +4189,68 @@ class Group extends CakeTestModel { */ class User2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'User2'; +/** + * name property + * + * @var string + */ + public $name = 'User2'; - /** - * table property - * - * @var string - */ - public $table = 'user'; +/** + * table property + * + * @var string + */ + public $table = 'user'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Group' => array( - 'className' => 'Group' - ), - 'Level' => array( - 'className' => 'Level' - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Group' => array( + 'className' => 'Group' + ), + 'Level' => array( + 'className' => 'Level' + ) + ); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Article2' => array( - 'className' => 'Article2' - ), - ); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Article2' => array( + 'className' => 'Article2' + ), + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'level_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4315,78 +4261,79 @@ class User2 extends CakeTestModel { */ class Category2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Category2'; +/** + * name property + * + * @var string + */ + public $name = 'Category2'; - /** - * table property - * - * @var string - */ - public $table = 'category'; +/** + * table property + * + * @var string + */ + public $table = 'category'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Group' => array( - 'className' => 'Group', - 'foreignKey' => 'group_id' - ), - 'ParentCat' => array( - 'className' => 'Category2', - 'foreignKey' => 'parent_id' - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Group' => array( + 'className' => 'Group', + 'foreignKey' => 'group_id' + ), + 'ParentCat' => array( + 'className' => 'Category2', + 'foreignKey' => 'parent_id' + ) + ); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'ChildCat' => array( - 'className' => 'Category2', - 'foreignKey' => 'parent_id' - ), - 'Article2' => array( - 'className' => 'Article2', - 'order' => 'Article2.published_date DESC', - 'foreignKey' => 'category_id', - 'limit' => '3') - ); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'ChildCat' => array( + 'className' => 'Category2', + 'foreignKey' => 'parent_id' + ), + 'Article2' => array( + 'className' => 'Article2', + 'order' => 'Article2.published_date DESC', + 'foreignKey' => 'category_id', + 'limit' => '3') + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'group_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null), - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'group_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'description' => array('type' => 'text', 'null' => false, 'default' => '', 'length' => null), + + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4397,68 +4344,68 @@ class Category2 extends CakeTestModel { */ class Article2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Article2'; +/** + * name property + * + * @var string + */ + public $name = 'Article2'; - /** - * table property - * - * @var string - */ - public $table = 'articles'; +/** + * table property + * + * @var string + */ + public $table = 'articles'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Category2' => array('className' => 'Category2'), - 'User2' => array('className' => 'User2') - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Category2' => array('className' => 'Category2'), + 'User2' => array('className' => 'User2') + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'rate_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'rate_sum' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'viewed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'version' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => '45'), - 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '200'), - 'intro' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'comments' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '4'), - 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'isdraft' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'allow_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), - 'moderate_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), - 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'multipage' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), - 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), - 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'rate_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'rate_sum' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'viewed' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'version' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => '45'), + 'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '200'), + 'intro' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'comments' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '4'), + 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'isdraft' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'allow_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), + 'moderate_comments' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'length' => '1'), + 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'multipage' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4469,44 +4416,44 @@ class Article2 extends CakeTestModel { */ class CategoryFeatured2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'CategoryFeatured2'; +/** + * name property + * + * @var string + */ + public $name = 'CategoryFeatured2'; - /** - * table property - * - * @var string - */ - public $table = 'category_featured'; +/** + * table property + * + * @var string + */ + public $table = 'category_featured'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), - 'description' => array('text' => 'string', 'null' => false, 'default' => '', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'parent_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'icon' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), + 'description' => array('text' => 'string', 'null' => false, 'default' => '', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4517,54 +4464,54 @@ class CategoryFeatured2 extends CakeTestModel { */ class Featured2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Featured2'; +/** + * name property + * + * @var string + */ + public $name = 'Featured2'; - /** - * table property - * - * @var string - */ - public $table = 'featured2'; +/** + * table property + * + * @var string + */ + public $table = 'featured2'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'CategoryFeatured2' => array( - 'className' => 'CategoryFeatured2' - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'CategoryFeatured2' => array( + 'className' => 'CategoryFeatured2' + ) + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'article_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'article_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'category_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4575,50 +4522,50 @@ class Featured2 extends CakeTestModel { */ class Comment2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'Comment2'; +/** + * name property + * + * @var string + */ + public $name = 'Comment2'; - /** - * table property - * - * @var string - */ - public $table = 'comment'; +/** + * table property + * + * @var string + */ + public $table = 'comment'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('ArticleFeatured2', 'User2'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('ArticleFeatured2', 'User2'); - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'article_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'article_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'name' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20') + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4629,76 +4576,76 @@ class Comment2 extends CakeTestModel { */ class ArticleFeatured2 extends CakeTestModel { - /** - * name property - * - * @var string - */ - public $name = 'ArticleFeatured2'; +/** + * name property + * + * @var string + */ + public $name = 'ArticleFeatured2'; - /** - * table property - * - * @var string - */ - public $table = 'article_featured'; +/** + * table property + * + * @var string + */ + public $table = 'article_featured'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'CategoryFeatured2' => array('className' => 'CategoryFeatured2'), - 'User2' => array('className' => 'User2') - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'CategoryFeatured2' => array('className' => 'CategoryFeatured2'), + 'User2' => array('className' => 'User2') + ); - /** - * hasOne property - * - * @var array - */ - public $hasOne = array( - 'Featured2' => array('className' => 'Featured2') - ); +/** + * hasOne property + * + * @var array + */ + public $hasOne = array( + 'Featured2' => array('className' => 'Featured2') + ); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Comment2' => array('className' => 'Comment2', 'dependent' => true) - ); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Comment2' => array('className' => 'Comment2', 'dependent' => true) + ); - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - if (!isset($this->_schema)) { - $this->_schema = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), - 'category_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), - 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), - 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), - 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), - 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), - 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), - 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) - ); +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + if (!isset($this->_schema)) { + $this->_schema = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => '10'), + 'category_featured_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => '10'), + 'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => '20'), + 'body' => array('text' => 'string', 'null' => true, 'default' => '', 'length' => null), + 'published' => array('type' => 'boolean', 'null' => false, 'default' => '0', 'length' => '1'), + 'published_date' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00', 'length' => null) + ); + } + return $this->_schema; } - return $this->_schema; - } } @@ -4709,73 +4656,73 @@ class ArticleFeatured2 extends CakeTestModel { */ class MysqlTestModel extends Model { - /** - * name property - * - * @var string - */ - public $name = 'MysqlTestModel'; +/** + * name property + * + * @var string + */ + public $name = 'MysqlTestModel'; - /** - * useTable property - * - * @var bool false - */ - public $useTable = false; +/** + * useTable property + * + * @var bool false + */ + public $useTable = false; - /** - * find method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function find($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } +/** + * find method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function find($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } - /** - * findAll method - * - * @param mixed $conditions - * @param mixed $fields - * @param mixed $order - * @param mixed $recursive - * @return void - */ - public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { - return $conditions; - } +/** + * findAll method + * + * @param mixed $conditions + * @param mixed $fields + * @param mixed $order + * @param mixed $recursive + * @return void + */ + public function findAll($conditions = null, $fields = null, $order = null, $recursive = null) { + return $conditions; + } - /** - * schema method - * - * @return void - */ - public function schema($field = false) { - return array( - 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), - 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), - 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), - 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), - 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), - 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), - 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''), - 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), - 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), - 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) - ); - } +/** + * schema method + * + * @return void + */ + public function schema($field = false) { + return array( + 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), + 'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'), + 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), + 'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'), + 'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'), + 'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'), + 'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''), + 'last_login' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''), + 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), + 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) + ); + } } @@ -4784,13 +4731,13 @@ class MysqlTestModel extends Model { * */ class PrefixTestModel extends CakeTestModel { - } class PrefixTestUseTableModel extends CakeTestModel { - public $name = 'PrefixTest'; - public $useTable = 'prefix_tests'; + public $name = 'PrefixTest'; + + public $useTable = 'prefix_tests'; } @@ -4801,50 +4748,50 @@ class PrefixTestUseTableModel extends CakeTestModel { */ class ScaffoldMock extends CakeTestModel { - /** - * useTable property - * - * @var string - */ - public $useTable = 'articles'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'articles'; - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'User' => array( - 'className' => 'ScaffoldUser', - 'foreignKey' => 'user_id', - ) - ); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'User' => array( + 'className' => 'ScaffoldUser', + 'foreignKey' => 'user_id', + ) + ); - /** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Comment' => array( - 'className' => 'ScaffoldComment', - 'foreignKey' => 'article_id', - ) - ); +/** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Comment' => array( + 'className' => 'ScaffoldComment', + 'foreignKey' => 'article_id', + ) + ); - /** - * hasAndBelongsToMany property - * - * @var string - */ - public $hasAndBelongsToMany = array( - 'ScaffoldTag' => array( - 'className' => 'ScaffoldTag', - 'foreignKey' => 'something_id', - 'associationForeignKey' => 'something_else_id', - 'joinTable' => 'join_things' - ) - ); +/** + * hasAndBelongsToMany property + * + * @var string + */ + public $hasAndBelongsToMany = array( + 'ScaffoldTag' => array( + 'className' => 'ScaffoldTag', + 'foreignKey' => 'something_id', + 'associationForeignKey' => 'something_else_id', + 'joinTable' => 'join_things' + ) + ); } @@ -4855,25 +4802,24 @@ class ScaffoldMock extends CakeTestModel { */ class ScaffoldUser extends CakeTestModel { - /** - * useTable property - * - * @var string - */ - public $useTable = 'users'; - - /** - * hasMany property - * - * @var array - */ - public $hasMany = array( - 'Article' => array( - 'className' => 'ScaffoldMock', - 'foreignKey' => 'article_id', - ) - ); +/** + * useTable property + * + * @var string + */ + public $useTable = 'users'; +/** + * hasMany property + * + * @var array + */ + public $hasMany = array( + 'Article' => array( + 'className' => 'ScaffoldMock', + 'foreignKey' => 'article_id', + ) + ); } /** @@ -4883,25 +4829,24 @@ class ScaffoldUser extends CakeTestModel { */ class ScaffoldComment extends CakeTestModel { - /** - * useTable property - * - * @var string - */ - public $useTable = 'comments'; - - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array( - 'Article' => array( - 'className' => 'ScaffoldMock', - 'foreignKey' => 'article_id', - ) - ); +/** + * useTable property + * + * @var string + */ + public $useTable = 'comments'; +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array( + 'Article' => array( + 'className' => 'ScaffoldMock', + 'foreignKey' => 'article_id', + ) + ); } /** @@ -4911,12 +4856,12 @@ class ScaffoldComment extends CakeTestModel { */ class ScaffoldTag extends CakeTestModel { - /** - * useTable property - * - * @var string - */ - public $useTable = 'tags'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'tags'; } @@ -4927,12 +4872,12 @@ class ScaffoldTag extends CakeTestModel { */ class Player extends CakeTestModel { - public $hasAndBelongsToMany = array( - 'Guild' => array( - 'with' => 'GuildsPlayer', - 'unique' => true, - ), - ); + public $hasAndBelongsToMany = array( + 'Guild' => array( + 'with' => 'GuildsPlayer', + 'unique' => true, + ), + ); } @@ -4943,12 +4888,12 @@ class Player extends CakeTestModel { */ class Guild extends CakeTestModel { - public $hasAndBelongsToMany = array( - 'Player' => array( - 'with' => 'GuildsPlayer', - 'unique' => true, - ), - ); + public $hasAndBelongsToMany = array( + 'Player' => array( + 'with' => 'GuildsPlayer', + 'unique' => true, + ), + ); } @@ -4959,12 +4904,12 @@ class Guild extends CakeTestModel { */ class GuildsPlayer extends CakeTestModel { - public $useDbConfig = 'test2'; - public $belongsTo = array( - 'Player', - 'Guild', - ); + public $useDbConfig = 'test2'; + public $belongsTo = array( + 'Player', + 'Guild', + ); } /** @@ -4974,11 +4919,11 @@ class GuildsPlayer extends CakeTestModel { */ class Armor extends CakeTestModel { - public $useDbConfig = 'test2'; - public $hasAndBelongsToMany = array( - 'Player' => array('with' => 'ArmorsPlayer'), - ); + public $useDbConfig = 'test2'; + public $hasAndBelongsToMany = array( + 'Player' => array('with' => 'ArmorsPlayer'), + ); } /** @@ -4988,7 +4933,7 @@ class Armor extends CakeTestModel { */ class ArmorsPlayer extends CakeTestModel { - public $useDbConfig = 'test_database_three'; + public $useDbConfig = 'test_database_three'; } @@ -4999,53 +4944,53 @@ class ArmorsPlayer extends CakeTestModel { */ class CustomArticle extends AppModel { - /** - * useTable property - * - * @var string - */ - public $useTable = 'articles'; +/** + * useTable property + * + * @var string + */ + public $useTable = 'articles'; - /** - * findMethods property - * - * @var array - */ - public $findMethods = array('unPublished' => true); +/** + * findMethods property + * + * @var array + */ + public $findMethods = array('unPublished' => true); - /** - * belongsTo property - * - * @var array - */ - public $belongsTo = array('User'); +/** + * belongsTo property + * + * @var array + */ + public $belongsTo = array('User'); - /** - * _findUnPublished custom find - * - * @return array - */ - protected function _findUnPublished($state, $query, $results = array()) { - if ($state === 'before') { - $query['conditions']['published'] = 'N'; - return $query; +/** + * _findUnPublished custom find + * + * @return array + */ + protected function _findUnPublished($state, $query, $results = array()) { + if ($state === 'before') { + $query['conditions']['published'] = 'N'; + return $query; + } + return $results; } - return $results; - } - /** - * Alters title data - * - * @return void - */ - public function beforeValidate($options = array()) { - $this->data[$this->alias]['title'] = 'foo'; - if ($this->findMethods['unPublished'] === true) { - $this->findMethods['unPublished'] = false; - } else { - $this->findMethods['unPublished'] = 'true again'; +/** + * Alters title data + * + * @return void + */ + public function beforeValidate($options = array()) { + $this->data[$this->alias]['title'] = 'foo'; + if ($this->findMethods['unPublished'] === true) { + $this->findMethods['unPublished'] = false; + } else { + $this->findMethods['unPublished'] = 'true again'; + } } - } } @@ -5065,18 +5010,17 @@ class ModelWithRelations extends CakeTestModel { */ class ModelRelated extends CakeTestModel { - /** - * afterFind callback method - * - * @param array $results - * @param boolean $primary - * @return array Modified $results - */ - public function afterFind($results, $primary = false) { - foreach ($results as $key => $result) { - $results[$key][$this->alias]['name'] = 'Successfuly changed in AfterFind'; + /** + * afterFind callback method + * + * @param array $results + * @param boolean $primary + * @return array Modified $results + */ + public function afterFind($results, $primary = false) { + foreach ($results as $key => $result) { + $results[$key][$this->alias]['name'] = 'Successfuly changed in AfterFind'; + } + return $results; } - return $results; - } - } diff --git a/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php b/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php index b75a2c3aa..f6ac65a70 100644 --- a/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php +++ b/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php @@ -26,27 +26,27 @@ */ class ModelHabtmRelationFixture extends CakeTestFixture { - /** - * fields property - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'primary_id' => array('type' => 'integer'), - 'related_id' => array('type' => 'integer'), - ); + /** + * fields property + * + * @var array + */ + public $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'primary_id' => array('type' => 'integer'), + 'related_id' => array('type' => 'integer'), + ); - /** - * records property - * - * @var array - */ - public $records = array( - array('id' => 1, 'primary_id' => 1, 'related_id' => 1), - array('id' => 2, 'primary_id' => 1, 'related_id' => 2), - array('id' => 3, 'primary_id' => 2, 'related_id' => 1), - array('id' => 4, 'primary_id' => 2, 'related_id' => 2), - ); + /** + * records property + * + * @var array + */ + public $records = array( + array('id' => 1, 'primary_id' => 1, 'related_id' => 1), + array('id' => 2, 'primary_id' => 1, 'related_id' => 2), + array('id' => 3, 'primary_id' => 2, 'related_id' => 1), + array('id' => 4, 'primary_id' => 2, 'related_id' => 2), + ); } diff --git a/lib/Cake/Test/Fixture/ModelRelatedFixture.php b/lib/Cake/Test/Fixture/ModelRelatedFixture.php index 94c7c3c42..b688ae8fc 100644 --- a/lib/Cake/Test/Fixture/ModelRelatedFixture.php +++ b/lib/Cake/Test/Fixture/ModelRelatedFixture.php @@ -26,25 +26,25 @@ */ class ModelRelatedFixture extends CakeTestFixture { - /** - * fields property - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'name' => array('type' => 'string'), - 'primary_id' => array('type' => 'integer'), - ); + /** + * fields property + * + * @var array + */ + public $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'name' => array('type' => 'string'), + 'primary_id' => array('type' => 'integer'), + ); - /** - * records property - * - * @var array - */ - public $records = array( - array('id' => 1, 'name' => 'This should change on afterFind', 'primary_id' => 1), - array('id' => 2, 'name' => 'This also should change on afterFind', 'primary_id' => 2) - ); + /** + * records property + * + * @var array + */ + public $records = array( + array('id' => 1, 'name' => 'This should change on afterFind', 'primary_id' => 1), + array('id' => 2, 'name' => 'This also should change on afterFind', 'primary_id' => 2) + ); } diff --git a/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php b/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php index ed7998896..6deac03c9 100644 --- a/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php +++ b/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php @@ -26,25 +26,25 @@ */ class ModelWithRelationsFixture extends CakeTestFixture { - /** - * fields property - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'name' => array('type' => 'string'), - 'related_id' => array('type' => 'integer'), - ); + /** + * fields property + * + * @var array + */ + public $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'name' => array('type' => 'string'), + 'related_id' => array('type' => 'integer'), + ); - /** - * records property - * - * @var array - */ - public $records = array( - array('id' => 1, 'name' => 'First record', 'related_id' => 1), - array('id' => 2, 'name' => 'Second record', 'related_id' => 2) - ); + /** + * records property + * + * @var array + */ + public $records = array( + array('id' => 1, 'name' => 'First record', 'related_id' => 1), + array('id' => 2, 'name' => 'Second record', 'related_id' => 2) + ); } From bb13af683bc0641aafb85f101def22c0e2f7253e Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 10:19:20 +0200 Subject: [PATCH 09/26] Added some test for related model afterFind callback --- lib/Cake/Model/Datasource/DboSource.php.orig | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/Cake/Model/Datasource/DboSource.php.orig diff --git a/lib/Cake/Model/Datasource/DboSource.php.orig b/lib/Cake/Model/Datasource/DboSource.php.orig new file mode 100644 index 000000000..e69de29bb From 0c1dbded6716ac673aa650d017cd56883bb5a473 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 10:19:48 +0200 Subject: [PATCH 10/26] Added some test for related model afterFind callback --- lib/Cake/Model/Datasource/DboSource.php.orig | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/Cake/Model/Datasource/DboSource.php.orig diff --git a/lib/Cake/Model/Datasource/DboSource.php.orig b/lib/Cake/Model/Datasource/DboSource.php.orig deleted file mode 100644 index e69de29bb..000000000 From a6efcae62597a9c7f35d2bd401557c17da373b19 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 12:32:36 +0200 Subject: [PATCH 11/26] Deleted rows in ModelReadTest --- lib/Cake/Test/Case/Model/ModelReadTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index e8bacb683..5aeb551c7 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -6302,7 +6302,7 @@ class ModelReadTest extends BaseModelTest { $this->loadFixtures('User'); $TestModel = new User(); $TestModel->cacheQueries = false; - + $TestModel->order = null; $expected = array( 'conditions' => array( 'user' => 'larry' @@ -6848,7 +6848,7 @@ class ModelReadTest extends BaseModelTest { 'user' => 'mariano' )); $this->assertEquals('mariano', $result); - + $TestModel->order = null; $result = $TestModel->field('COUNT(*) AS count', true); $this->assertEquals(4, $result); @@ -6904,6 +6904,7 @@ class ModelReadTest extends BaseModelTest { $this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']); $Article = new Article(); + $Article->order = null; $Article->recursive = -1; $expected = count($Article->find('all', array( 'fields' => array('Article.user_id'), @@ -7760,6 +7761,7 @@ class ModelReadTest extends BaseModelTest { 'limit' => 1 )); $this->assertEquals(2, $result['Post']['id']); + $Post->order = null; $Post->virtualFields = array('other_field' => 'Post.id + 1'); $result = $Post->find('all', array( From 50cf0707270a4b369a3674cc97b5592b2f43452b Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 12:59:30 +0200 Subject: [PATCH 12/26] Formatting issues --- lib/Cake/Test/Case/Model/ModelReadTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 5aeb551c7..abf3fd33a 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -7761,7 +7761,7 @@ class ModelReadTest extends BaseModelTest { 'limit' => 1 )); $this->assertEquals(2, $result['Post']['id']); - $Post->order = null; + $Post->order = null; $Post->virtualFields = array('other_field' => 'Post.id + 1'); $result = $Post->find('all', array( @@ -7967,12 +7967,12 @@ class ModelReadTest extends BaseModelTest { $result = $Article->find('unPublished'); $this->assertEquals(1, count($result)); } - + /** -* test after find callback on related model -* -* @return void -*/ + * test after find callback on related model + * + * @return void + */ public function testRelatedAfterFindCallback() { $this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation'); $ModelWithRelations = new ModelWithRelations(); @@ -8014,14 +8014,14 @@ class ModelReadTest extends BaseModelTest { ) ); $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail'); - + $ModelWithRelations->bindModel(array( 'hasOne' => array( 'HasOne' => array( 'className' => 'ModelRelated', 'foreignKey' => 'primary_id', ) - ) + ) ) ); $results = $ModelWithRelations->find('all'); @@ -8052,7 +8052,7 @@ class ModelReadTest extends BaseModelTest { ) ); $this->assertEquals($expected, $results, 'Model related with hasOne afterFind callback fail'); - + $ModelWithRelations->bindModel(array( 'hasMany' => array( 'HasMany' => array( From 2235a0e677be1a8cbd26bae08de2eba601201fc1 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 13:00:12 +0200 Subject: [PATCH 13/26] Formatting issues --- lib/Cake/Test/Case/Model/ModelTestBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelTestBase.php b/lib/Cake/Test/Case/Model/ModelTestBase.php index 73ae9c606..c3361ef96 100644 --- a/lib/Cake/Test/Case/Model/ModelTestBase.php +++ b/lib/Cake/Test/Case/Model/ModelTestBase.php @@ -72,7 +72,7 @@ abstract class BaseModelTest extends CakeTestCase { 'core.fruits_uuid_tag', 'core.uuid_tag', 'core.product_update_all', 'core.group_update_all', 'core.player', 'core.guild', 'core.guilds_player', 'core.armor', 'core.armors_player', 'core.bidding', 'core.bidding_message', 'core.site', 'core.domain', 'core.domains_site', - 'core.model_with_relations','core.model_related','core.model_habtm_relation', + 'core.model_with_relations', 'core.model_related', 'core.model_habtm_relation', ); /** From 1d9bce34d4e86f672ad8f4ed2d6e3333ff3f138f Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 13:01:38 +0200 Subject: [PATCH 14/26] Formatting issues --- lib/Cake/Test/Case/Model/models.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index f91d79a81..c6cd00048 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -5000,7 +5000,7 @@ class CustomArticle extends AppModel { * @package Cake.Test.Case.Model */ class ModelWithRelations extends CakeTestModel { - + } /** @@ -5010,13 +5010,13 @@ class ModelWithRelations extends CakeTestModel { */ class ModelRelated extends CakeTestModel { - /** - * afterFind callback method - * - * @param array $results - * @param boolean $primary - * @return array Modified $results - */ +/** + * afterFind callback method + * + * @param array $results + * @param boolean $primary + * @return array Modified $results + */ public function afterFind($results, $primary = false) { foreach ($results as $key => $result) { $results[$key][$this->alias]['name'] = 'Successfuly changed in AfterFind'; From b5a8a6f94626729d2c9e7f7511a643fddd635edb Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 13:02:33 +0200 Subject: [PATCH 15/26] Formatting issues --- .../Fixture/ModelHabtmRelationFixture.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php b/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php index f6ac65a70..3376f713c 100644 --- a/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php +++ b/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php @@ -26,22 +26,22 @@ */ class ModelHabtmRelationFixture extends CakeTestFixture { - /** - * fields property - * - * @var array - */ +/** + * fields property + * + * @var array + */ public $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), 'primary_id' => array('type' => 'integer'), 'related_id' => array('type' => 'integer'), ); - /** - * records property - * - * @var array - */ +/** + * records property + * + * @var array + */ public $records = array( array('id' => 1, 'primary_id' => 1, 'related_id' => 1), array('id' => 2, 'primary_id' => 1, 'related_id' => 2), From 8a8db72b7c9ba565c9cf922ae08f07263cf18389 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 13:03:19 +0200 Subject: [PATCH 16/26] Formatting issues --- lib/Cake/Test/Fixture/ModelRelatedFixture.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Fixture/ModelRelatedFixture.php b/lib/Cake/Test/Fixture/ModelRelatedFixture.php index b688ae8fc..184af82c7 100644 --- a/lib/Cake/Test/Fixture/ModelRelatedFixture.php +++ b/lib/Cake/Test/Fixture/ModelRelatedFixture.php @@ -26,22 +26,22 @@ */ class ModelRelatedFixture extends CakeTestFixture { - /** - * fields property - * - * @var array - */ +/** + * fields property + * + * @var array + */ public $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), 'name' => array('type' => 'string'), 'primary_id' => array('type' => 'integer'), ); - /** - * records property - * - * @var array - */ +/** + * records property + * + * @var array + */ public $records = array( array('id' => 1, 'name' => 'This should change on afterFind', 'primary_id' => 1), array('id' => 2, 'name' => 'This also should change on afterFind', 'primary_id' => 2) From bb7ff48b01f94809a4a9f126d8a3ec1a981e2417 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Tue, 13 Aug 2013 14:03:20 +0200 Subject: [PATCH 17/26] Formatting issues --- .../Fixture/ModelWithRelationsFixture.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php b/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php index 6deac03c9..6e4fd945e 100644 --- a/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php +++ b/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php @@ -26,22 +26,22 @@ */ class ModelWithRelationsFixture extends CakeTestFixture { - /** - * fields property - * - * @var array - */ +/** + * fields property + * + * @var array + */ public $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), 'name' => array('type' => 'string'), 'related_id' => array('type' => 'integer'), ); - /** - * records property - * - * @var array - */ +/** + * records property + * + * @var array + */ public $records = array( array('id' => 1, 'name' => 'First record', 'related_id' => 1), array('id' => 2, 'name' => 'Second record', 'related_id' => 2) From d7dab3282f7d9896c19235d1cd280d6960ab2ced Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 16 Aug 2013 09:28:32 +0200 Subject: [PATCH 18/26] Remove added fixtures and use existing. Updated one old test to add data from afterFind callback --- .../Test/Case/Model/ModelIntegrationTest.php | 66 ++- lib/Cake/Test/Case/Model/ModelReadTest.php | 400 ++++++++++-------- lib/Cake/Test/Case/Model/ModelTestBase.php | 1 - lib/Cake/Test/Case/Model/models.php | 65 +-- .../Fixture/ModelHabtmRelationFixture.php | 52 --- lib/Cake/Test/Fixture/ModelRelatedFixture.php | 50 --- .../Fixture/ModelWithRelationsFixture.php | 50 --- 7 files changed, 299 insertions(+), 385 deletions(-) delete mode 100644 lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php delete mode 100644 lib/Cake/Test/Fixture/ModelRelatedFixture.php delete mode 100644 lib/Cake/Test/Fixture/ModelWithRelationsFixture.php diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index 1ab298c04..4c6921376 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -1708,7 +1708,8 @@ class ModelIntegrationTest extends BaseModelTest { 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' + 'updated' => '2007-03-18 10:41:31', + 'afterFind' => 'Successfuly added by AfterFind' ), 'Something' => array( array( @@ -1724,7 +1725,8 @@ class ModelIntegrationTest extends BaseModelTest { 'something_else_id' => '1', 'doomed' => true, 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' + 'updated' => '2007-03-18 10:45:31', + 'afterFind' => 'Successfuly added by AfterFind' )))), array( 'SomethingElse' => array( @@ -1733,7 +1735,8 @@ class ModelIntegrationTest extends BaseModelTest { 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' + 'updated' => '2007-03-18 10:43:31', + 'afterFind' => 'Successfuly added by AfterFind' ), 'Something' => array( array( @@ -1749,7 +1752,8 @@ class ModelIntegrationTest extends BaseModelTest { 'something_else_id' => '2', 'doomed' => true, 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' + 'updated' => '2007-03-18 10:41:31', + 'afterFind' => 'Successfuly added by AfterFind' )))), array( 'SomethingElse' => array( @@ -1758,7 +1762,8 @@ class ModelIntegrationTest extends BaseModelTest { 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' + 'updated' => '2007-03-18 10:45:31', + 'afterFind' => 'Successfuly added by AfterFind' ), 'Something' => array( array( @@ -1774,7 +1779,8 @@ class ModelIntegrationTest extends BaseModelTest { 'something_else_id' => '3', 'doomed' => false, 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' + 'updated' => '2007-03-18 10:43:31', + 'afterFind' => 'Successfuly added by AfterFind' ))))); $this->assertEquals($expected, $result); @@ -1800,8 +1806,11 @@ class ModelIntegrationTest extends BaseModelTest { 'JoinThing' => array( 'doomed' => true, 'something_id' => '1', - 'something_else_id' => '2' - )))), + 'something_else_id' => '2', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'afterFind' => 'Successfuly added by AfterFind' + ))), array( 'Something' => array( 'id' => '2', @@ -1822,8 +1831,11 @@ class ModelIntegrationTest extends BaseModelTest { 'JoinThing' => array( 'doomed' => false, 'something_id' => '2', - 'something_else_id' => '3' - )))), + 'something_else_id' => '3', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'afterFind' => 'Successfuly added by AfterFind' + ))), array( 'Something' => array( 'id' => '3', @@ -1844,8 +1856,11 @@ class ModelIntegrationTest extends BaseModelTest { 'JoinThing' => array( 'doomed' => true, 'something_id' => '3', - 'something_else_id' => '1' - ))))); + 'something_else_id' => '1', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'afterFind' => 'Successfuly added by AfterFind' + )))); $this->assertEquals($expected, $result); $result = $TestModel->findById(1); @@ -1869,8 +1884,11 @@ class ModelIntegrationTest extends BaseModelTest { 'JoinThing' => array( 'doomed' => true, 'something_id' => '1', - 'something_else_id' => '2' - )))); + 'something_else_id' => '2', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'afterFind' => 'Successfuly added by AfterFind' + ))); $this->assertEquals($expected, $result); $expected = $TestModel->findById(1); @@ -1910,8 +1928,10 @@ class ModelIntegrationTest extends BaseModelTest { 'JoinThing' => array( 'doomed' => true, 'something_id' => '1', - 'something_else_id' => '1' - ) + 'something_else_id' => '1', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'afterFind' => 'Successfuly added by AfterFind' ), array( 'id' => '2', @@ -1923,8 +1943,10 @@ class ModelIntegrationTest extends BaseModelTest { 'JoinThing' => array( 'doomed' => true, 'something_id' => '1', - 'something_else_id' => '2' - ) + 'something_else_id' => '2', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'afterFind' => 'Successfuly added by AfterFind' ), array( 'id' => '3', @@ -1936,10 +1958,12 @@ class ModelIntegrationTest extends BaseModelTest { 'JoinThing' => array( 'doomed' => false, 'something_id' => '1', - 'something_else_id' => '3') - ) + 'something_else_id' => '3', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'afterFind' => 'Successfuly added by AfterFind' ) - ); + )); $this->assertEquals(self::date(), $result['Something']['updated']); unset($result['Something']['updated']); $this->assertEquals($expected, $result); diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index abf3fd33a..627ad8dba 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -7974,201 +7974,243 @@ class ModelReadTest extends BaseModelTest { * @return void */ public function testRelatedAfterFindCallback() { - $this->loadFixtures('ModelWithRelations', 'ModelRelated', 'ModelHabtmRelation'); - $ModelWithRelations = new ModelWithRelations(); - - $ModelWithRelations->bindModel(array( - 'belongsTo' => array( - 'BelongsTo' => array( - 'className' => 'ModelRelated', - 'foreignKey' => 'related_id', + $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); + $Something = new Something(); + + $Something->bindModel(array( + 'hasMany' => array( + 'HasMany' => array( + 'className' => 'JoinThing', + 'foreignKey' => 'something_id' + ) + ), + 'hasOne'=>array( + 'HasOne'=>array( + 'className' => 'JoinThing', + 'foreignKey' => 'something_id' ) ) - ) - ); - $results = $ModelWithRelations->find('all'); + ) + ); + + $results = $Something->find('all'); + $expected = array( array( - 'ModelWithRelations' => array( + 'Something' => array( 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' ), - 'BelongsTo' => array( + 'HasOne' => array( 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1' + 'something_id' => '1', + 'something_else_id' => '2', + 'doomed' => true, + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'HasMany' => array( + array( + 'id' => '1', + 'something_id' => '1', + 'something_else_id' => '2', + 'doomed' => true, + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ), + 'SomethingElse' => array( + array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'afterFind' => 'Successfuly added by AfterFind', + 'JoinThing' => array( + 'doomed' => true, + 'something_id' => '1', + 'something_else_id' => '2', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ) ) ), array( - 'ModelWithRelations' => array( + 'Something' => array( 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' ), - 'BelongsTo' => array( + 'HasOne' => array( 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2' + 'something_id' => '2', + 'something_else_id' => '3', + 'doomed' => false, + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'HasMany' => array( + array( + 'id' => '2', + 'something_id' => '2', + 'something_else_id' => '3', + 'doomed' => false, + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ), + 'SomethingElse' => array( + array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'afterFind' => 'Successfuly added by AfterFind', + 'JoinThing' => array( + 'doomed' => false, + 'something_id' => '2', + 'something_else_id' => '3', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ) + ) + ), + array( + 'Something' => array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'HasOne' => array( + 'id' => '3', + 'something_id' => '3', + 'something_else_id' => '1', + 'doomed' => true, + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'HasMany' => array( + array( + 'id' => '3', + 'something_id' => '3', + 'something_else_id' => '1', + 'doomed' => true, + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ), + 'SomethingElse' => array( + array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'afterFind' => 'Successfuly added by AfterFind', + 'JoinThing' => array( + 'doomed' => true, + 'something_id' => '3', + 'something_else_id' => '1', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ) + ) + ) + ); + $this->assertEquals($expected, $results, 'Model related with has* afterFind callback fail'); + + $JoinThing = new JoinThing(); + $JoinThing->unbindModel(array( + 'belongsTo'=>array( + 'Something' + ) + ) + ); + $results = $JoinThing->find('all'); + + $expected = array( + array( + 'JoinThing' => array( + 'id' => '1', + 'something_id' => '1', + 'something_else_id' => '2', + 'doomed' => true, + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'SomethingElse' => array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ), + array( + 'JoinThing' => array( + 'id' => '2', + 'something_id' => '2', + 'something_else_id' => '3', + 'doomed' => false, + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'SomethingElse' => array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'afterFind' => 'Successfuly added by AfterFind' + ) + ), + array( + 'JoinThing' => array( + 'id' => '3', + 'something_id' => '3', + 'something_else_id' => '1', + 'doomed' => true, + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'afterFind' => 'Successfuly added by AfterFind' + ), + 'SomethingElse' => array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'afterFind' => 'Successfuly added by AfterFind' ) ) ); $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail'); - - $ModelWithRelations->bindModel(array( - 'hasOne' => array( - 'HasOne' => array( - 'className' => 'ModelRelated', - 'foreignKey' => 'primary_id', - ) - ) - ) - ); - $results = $ModelWithRelations->find('all'); - $expected = array( - array( - 'ModelWithRelations' => array( - 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' - ), - 'HasOne' => array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1' - ) - ), - array( - 'ModelWithRelations' => array( - 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' - ), - 'HasOne' => array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2' - ) - ) - ); - $this->assertEquals($expected, $results, 'Model related with hasOne afterFind callback fail'); - - $ModelWithRelations->bindModel(array( - 'hasMany' => array( - 'HasMany' => array( - 'className' => 'ModelRelated', - 'foreignKey' => 'primary_id', - ) - ) - ) - ); - $results = $ModelWithRelations->find('all'); - - $expected = array( - array( - 'ModelWithRelations' => array( - 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' - ), - 'HasMany' => array( - array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1' - ) - ) - ), - array( - 'ModelWithRelations' => array( - 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' - ), - 'HasMany' => array( - array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2' - ) - ) - ) - ); - $this->assertEquals($expected, $results, 'Model related with hasMany afterFind callback fail'); - - $ModelWithRelations->bindModel(array( - 'hasAndBelongsToMany' => array( - 'HasAndBelongsToMany' => array( - 'className' => 'ModelRelated', - 'with' => 'ModelHabtmRelation', - 'foreignKey' => 'primary_id', - 'associationForeignKey' => 'related_id', - ) - ) - ) - ); - $results = $ModelWithRelations->find('all'); - - $expected = array( - array( - 'ModelWithRelations' => array( - 'id' => '1', - 'name' => 'First record', - 'related_id' => '1' - ), - 'HasAndBelongsToMany' => array( - array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1', - 'ModelHabtmRelation' => array( - 'id' => '1', - 'primary_id' => '1', - 'related_id' => '1' - ) - ), - array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2', - 'ModelHabtmRelation' => array( - 'id' => '2', - 'primary_id' => '1', - 'related_id' => '2' - ) - ) - ) - ), - array( - 'ModelWithRelations' => array( - 'id' => '2', - 'name' => 'Second record', - 'related_id' => '2' - ), - 'HasAndBelongsToMany' => array( - array( - 'id' => '1', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '1', - 'ModelHabtmRelation' => array( - 'id' => '3', - 'primary_id' => '2', - 'related_id' => '1' - ) - ), - array( - 'id' => '2', - 'name' => 'Successfuly changed in AfterFind', - 'primary_id' => '2', - 'ModelHabtmRelation' => array( - 'id' => '4', - 'primary_id' => '2', - 'related_id' => '2' - ) - ) - ) - ) - ); - $this->assertEquals($expected, $results, 'Model related with hasAndBelongsToMany afterFind callback fail'); } } diff --git a/lib/Cake/Test/Case/Model/ModelTestBase.php b/lib/Cake/Test/Case/Model/ModelTestBase.php index c3361ef96..16bffd8b4 100644 --- a/lib/Cake/Test/Case/Model/ModelTestBase.php +++ b/lib/Cake/Test/Case/Model/ModelTestBase.php @@ -72,7 +72,6 @@ abstract class BaseModelTest extends CakeTestCase { 'core.fruits_uuid_tag', 'core.uuid_tag', 'core.product_update_all', 'core.group_update_all', 'core.player', 'core.guild', 'core.guilds_player', 'core.armor', 'core.armors_player', 'core.bidding', 'core.bidding_message', 'core.site', 'core.domain', 'core.domains_site', - 'core.model_with_relations', 'core.model_related', 'core.model_habtm_relation', ); /** diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index c6cd00048..8b90fa49d 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -1501,6 +1501,22 @@ class SomethingElse extends CakeTestModel { * @var array */ public $hasAndBelongsToMany = array('Something' => array('with' => 'JoinThing')); + +/** + * afterFind callBack + * + * @param array $results + * @param bool $primary + * @return array + */ + public function afterFind($results, $primary = false) { + foreach ($results as $key => $result) { + if(!empty($result[$this->alias]) && is_array($result[$this->alias])){ + $results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind'; + } + } + return $results; + } } /** @@ -1523,6 +1539,22 @@ class JoinThing extends CakeTestModel { * @var array */ public $belongsTo = array('Something', 'SomethingElse'); + +/** + * afterFind callBack + * + * @param array $results + * @param bool $primary + * @return array + */ + public function afterFind($results, $primary = false) { + foreach ($results as $key => $result) { + if(!empty($result[$this->alias]) && is_array($result[$this->alias])){ + $results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind'; + } + } + return $results; + } } /** @@ -4992,35 +5024,4 @@ class CustomArticle extends AppModel { } } -} - -/** - * ModelWithRelations class - * - * @package Cake.Test.Case.Model - */ -class ModelWithRelations extends CakeTestModel { - -} - -/** - * ModelRelated class - * - * @package Cake.Test.Case.Model - */ -class ModelRelated extends CakeTestModel { - -/** - * afterFind callback method - * - * @param array $results - * @param boolean $primary - * @return array Modified $results - */ - public function afterFind($results, $primary = false) { - foreach ($results as $key => $result) { - $results[$key][$this->alias]['name'] = 'Successfuly changed in AfterFind'; - } - return $results; - } -} +} \ No newline at end of file diff --git a/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php b/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php deleted file mode 100644 index 3376f713c..000000000 --- a/lib/Cake/Test/Fixture/ModelHabtmRelationFixture.php +++ /dev/null @@ -1,52 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @package Cake.Test.Fixture - * @since CakePHP(tm) v 1.2.0.4667 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ - -/** - * Class PrimaryRelatedFixture - * - * @package Cake.Test.Fixture - */ -class ModelHabtmRelationFixture extends CakeTestFixture { - -/** - * fields property - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'primary_id' => array('type' => 'integer'), - 'related_id' => array('type' => 'integer'), - ); - -/** - * records property - * - * @var array - */ - public $records = array( - array('id' => 1, 'primary_id' => 1, 'related_id' => 1), - array('id' => 2, 'primary_id' => 1, 'related_id' => 2), - array('id' => 3, 'primary_id' => 2, 'related_id' => 1), - array('id' => 4, 'primary_id' => 2, 'related_id' => 2), - ); - -} diff --git a/lib/Cake/Test/Fixture/ModelRelatedFixture.php b/lib/Cake/Test/Fixture/ModelRelatedFixture.php deleted file mode 100644 index 184af82c7..000000000 --- a/lib/Cake/Test/Fixture/ModelRelatedFixture.php +++ /dev/null @@ -1,50 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @package Cake.Test.Fixture - * @since CakePHP(tm) v 1.2.0.4667 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ - -/** - * Class RelatedFixture - * - * @package Cake.Test.Fixture - */ -class ModelRelatedFixture extends CakeTestFixture { - -/** - * fields property - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'name' => array('type' => 'string'), - 'primary_id' => array('type' => 'integer'), - ); - -/** - * records property - * - * @var array - */ - public $records = array( - array('id' => 1, 'name' => 'This should change on afterFind', 'primary_id' => 1), - array('id' => 2, 'name' => 'This also should change on afterFind', 'primary_id' => 2) - ); - -} diff --git a/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php b/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php deleted file mode 100644 index 6e4fd945e..000000000 --- a/lib/Cake/Test/Fixture/ModelWithRelationsFixture.php +++ /dev/null @@ -1,50 +0,0 @@ - - * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * For full copyright and license information, please see the LICENSE.txt - * Redistributions of files must retain the above copyright notice - * - * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests - * @package Cake.Test.Fixture - * @since CakePHP(tm) v 1.2.0.4667 - * @license http://www.opensource.org/licenses/mit-license.php MIT License - */ - -/** - * Class PrimaryFixture - * - * @package Cake.Test.Fixture - */ -class ModelWithRelationsFixture extends CakeTestFixture { - -/** - * fields property - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'key' => 'primary'), - 'name' => array('type' => 'string'), - 'related_id' => array('type' => 'integer'), - ); - -/** - * records property - * - * @var array - */ - public $records = array( - array('id' => 1, 'name' => 'First record', 'related_id' => 1), - array('id' => 2, 'name' => 'Second record', 'related_id' => 2) - ); - -} From f5daf1c8aa551a229c6f3494e46fc7831a5a3aa3 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 16 Aug 2013 09:51:01 +0200 Subject: [PATCH 19/26] Fixed some formatting --- lib/Cake/Test/Case/Model/ModelReadTest.php | 12 ++++++------ lib/Cake/Test/Case/Model/models.php | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 627ad8dba..8c654501e 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -7984,17 +7984,17 @@ class ModelReadTest extends BaseModelTest { 'foreignKey' => 'something_id' ) ), - 'hasOne'=>array( - 'HasOne'=>array( + 'hasOne' => array( + 'HasOne' => array( 'className' => 'JoinThing', 'foreignKey' => 'something_id' ) ) ) ); - + $results = $Something->find('all'); - + $expected = array( array( 'Something' => array( @@ -8142,13 +8142,13 @@ class ModelReadTest extends BaseModelTest { $JoinThing = new JoinThing(); $JoinThing->unbindModel(array( - 'belongsTo'=>array( + 'belongsTo' => array( 'Something' ) ) ); $results = $JoinThing->find('all'); - + $expected = array( array( 'JoinThing' => array( diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index 8b90fa49d..5dc7204bf 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -1511,12 +1511,13 @@ class SomethingElse extends CakeTestModel { */ public function afterFind($results, $primary = false) { foreach ($results as $key => $result) { - if(!empty($result[$this->alias]) && is_array($result[$this->alias])){ + if (!empty($result[$this->alias]) && is_array($result[$this->alias])) { $results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind'; } } return $results; } + } /** @@ -1549,12 +1550,13 @@ class JoinThing extends CakeTestModel { */ public function afterFind($results, $primary = false) { foreach ($results as $key => $result) { - if(!empty($result[$this->alias]) && is_array($result[$this->alias])){ + if( !empty($result[$this->alias]) && is_array($result[$this->alias])) { $results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind'; } } return $results; } + } /** From 180ecb7929e3dde8286162418dd1834cb244135a Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 16 Aug 2013 10:02:11 +0200 Subject: [PATCH 20/26] Fixed some formatting --- lib/Cake/Test/Case/Model/models.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index 5dc7204bf..e18ef2596 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -1550,7 +1550,7 @@ class JoinThing extends CakeTestModel { */ public function afterFind($results, $primary = false) { foreach ($results as $key => $result) { - if( !empty($result[$this->alias]) && is_array($result[$this->alias])) { + if (!empty($result[$this->alias]) && is_array($result[$this->alias])) { $results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind'; } } From 391d997c2778801f5a47b24cce013d722ce0d834 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Fri, 16 Aug 2013 10:02:50 +0200 Subject: [PATCH 21/26] Fixed some formatting --- lib/Cake/Test/Case/Model/ModelReadTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 8c654501e..ac6eaa0b2 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -7976,7 +7976,7 @@ class ModelReadTest extends BaseModelTest { public function testRelatedAfterFindCallback() { $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); $Something = new Something(); - + $Something->bindModel(array( 'hasMany' => array( 'HasMany' => array( From 2a27b37a433b6077ac5f11e1c3e698202682e23f Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Sun, 18 Aug 2013 17:37:34 +0200 Subject: [PATCH 22/26] New line on end --- lib/Cake/Test/Case/Model/models.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index e18ef2596..33519b55c 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -5026,4 +5026,4 @@ class CustomArticle extends AppModel { } } -} \ No newline at end of file +} From 39f9d40be4e74b8b9c28e79614908c9b20ef8174 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Sun, 18 Aug 2013 17:41:43 +0200 Subject: [PATCH 23/26] Fixed formaiing and Successfully --- lib/Cake/Test/Case/Model/ModelReadTest.php | 46 +++++++++++----------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index ac6eaa0b2..1050b329d 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -7990,8 +7990,7 @@ class ModelReadTest extends BaseModelTest { 'foreignKey' => 'something_id' ) ) - ) - ); + )); $results = $Something->find('all'); @@ -8012,7 +8011,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'HasMany' => array( array( @@ -8022,7 +8021,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ), 'SomethingElse' => array( @@ -8033,12 +8032,12 @@ class ModelReadTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'afterFind' => 'Successfuly added by AfterFind', + 'afterFind' => 'Successfully added by AfterFind', 'JoinThing' => array( 'doomed' => true, 'something_id' => '1', 'something_else_id' => '2', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ) ) @@ -8059,7 +8058,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => false, 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'HasMany' => array( array( @@ -8069,7 +8068,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => false, 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ), 'SomethingElse' => array( @@ -8080,12 +8079,12 @@ class ModelReadTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'afterFind' => 'Successfuly added by AfterFind', + 'afterFind' => 'Successfully added by AfterFind', 'JoinThing' => array( 'doomed' => false, 'something_id' => '2', 'something_else_id' => '3', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ) ) @@ -8106,7 +8105,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'HasMany' => array( array( @@ -8116,7 +8115,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ), 'SomethingElse' => array( @@ -8127,26 +8126,25 @@ class ModelReadTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'afterFind' => 'Successfuly added by AfterFind', + 'afterFind' => 'Successfully added by AfterFind', 'JoinThing' => array( 'doomed' => true, 'something_id' => '3', 'something_else_id' => '1', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ) ) ) ); - $this->assertEquals($expected, $results, 'Model related with has* afterFind callback fail'); + $this->assertEquals($expected, $results, 'Model related with has* afterFind callback fails'); $JoinThing = new JoinThing(); $JoinThing->unbindModel(array( 'belongsTo' => array( 'Something' ) - ) - ); + )); $results = $JoinThing->find('all'); $expected = array( @@ -8158,7 +8156,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'SomethingElse' => array( 'id' => '2', @@ -8167,7 +8165,7 @@ class ModelReadTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ), array( @@ -8178,7 +8176,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => false, 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'SomethingElse' => array( 'id' => '3', @@ -8187,7 +8185,7 @@ class ModelReadTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ), array( @@ -8198,7 +8196,7 @@ class ModelReadTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'SomethingElse' => array( 'id' => '1', @@ -8207,10 +8205,10 @@ class ModelReadTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) ) ); - $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fail'); + $this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fails'); } } From 2166b397bcdc27495db394d65766e331dacff097 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Sun, 18 Aug 2013 17:43:26 +0200 Subject: [PATCH 24/26] Successfully --- lib/Cake/Test/Case/Model/models.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index 33519b55c..04bad57aa 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -1512,7 +1512,7 @@ class SomethingElse extends CakeTestModel { public function afterFind($results, $primary = false) { foreach ($results as $key => $result) { if (!empty($result[$this->alias]) && is_array($result[$this->alias])) { - $results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind'; + $results[$key][$this->alias]['afterFind'] = 'Successfully added by AfterFind'; } } return $results; From 9536b3cacd5802b6fe29e1ebeed1c3350305a27c Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Mon, 19 Aug 2013 08:11:45 +0200 Subject: [PATCH 25/26] Successfully --- lib/Cake/Test/Case/Model/models.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/models.php b/lib/Cake/Test/Case/Model/models.php index 04bad57aa..fe1d19de1 100644 --- a/lib/Cake/Test/Case/Model/models.php +++ b/lib/Cake/Test/Case/Model/models.php @@ -1551,7 +1551,7 @@ class JoinThing extends CakeTestModel { public function afterFind($results, $primary = false) { foreach ($results as $key => $result) { if (!empty($result[$this->alias]) && is_array($result[$this->alias])) { - $results[$key][$this->alias]['afterFind'] = 'Successfuly added by AfterFind'; + $results[$key][$this->alias]['afterFind'] = 'Successfully added by AfterFind'; } } return $results; From 9ad75e078a2c4fb691f2ea13f6ea15945a344d55 Mon Sep 17 00:00:00 2001 From: k-halaburda Date: Mon, 19 Aug 2013 08:29:39 +0200 Subject: [PATCH 26/26] Successfully :) --- .../Test/Case/Model/ModelIntegrationTest.php | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index 4c6921376..744f78044 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -1709,7 +1709,7 @@ class ModelIntegrationTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'Something' => array( array( @@ -1726,7 +1726,7 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' )))), array( 'SomethingElse' => array( @@ -1736,7 +1736,7 @@ class ModelIntegrationTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'Something' => array( array( @@ -1753,7 +1753,7 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => true, 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' )))), array( 'SomethingElse' => array( @@ -1763,7 +1763,7 @@ class ModelIntegrationTest extends BaseModelTest { 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), 'Something' => array( array( @@ -1780,7 +1780,7 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => false, 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ))))); $this->assertEquals($expected, $result); @@ -1807,9 +1807,9 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => true, 'something_id' => '1', 'something_else_id' => '2', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ))), array( 'Something' => array( @@ -1832,9 +1832,9 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => false, 'something_id' => '2', 'something_else_id' => '3', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ))), array( 'Something' => array( @@ -1857,9 +1857,9 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => true, 'something_id' => '3', 'something_else_id' => '1', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' )))); $this->assertEquals($expected, $result); @@ -1885,9 +1885,9 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => true, 'something_id' => '1', 'something_else_id' => '2', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ))); $this->assertEquals($expected, $result); @@ -1929,9 +1929,9 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => true, 'something_id' => '1', 'something_else_id' => '1', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), array( 'id' => '2', @@ -1944,9 +1944,9 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => true, 'something_id' => '1', 'something_else_id' => '2', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), array( 'id' => '3', @@ -1959,9 +1959,9 @@ class ModelIntegrationTest extends BaseModelTest { 'doomed' => false, 'something_id' => '1', 'something_else_id' => '3', - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ), - 'afterFind' => 'Successfuly added by AfterFind' + 'afterFind' => 'Successfully added by AfterFind' ) )); $this->assertEquals(self::date(), $result['Something']['updated']);