diff --git a/cake/libs/model/behaviors/containable.php b/cake/libs/model/behaviors/containable.php
new file mode 100644
index 000000000..7d9a96536
--- /dev/null
+++ b/cake/libs/model/behaviors/containable.php
@@ -0,0 +1,394 @@
+
+ * Copyright 2005-2008, Cake Software Foundation, Inc.
+ * 1785 E. Sahara Avenue, Suite 490-204
+ * Las Vegas, Nevada 89104
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
+ * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @package cake
+ * @subpackage cake.cake.console.libs
+ * @since CakePHP(tm) v 1.2.0.5669
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+/**
+ * Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting
+ * the amount of associations and data returned.
+ *
+ * @package cake
+ * @subpackage cake.cake.console.libs
+ */
+class ContainableBehavior extends ModelBehavior {
+/**
+ * Types of relationships available for models
+ *
+ * @var array
+ * @access private
+ */
+ var $types = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
+/**
+ * Runtime configuration for this behavior
+ *
+ * @var array
+ * @access private
+ */
+ var $runtime = array();
+/**
+ * Initiate behavior for the model using specified settings. Available settings:
+ *
+ * - recursive: (boolean, optional) set to true to allow containable to automatically
+ * determine the recursiveness level needed to fetch specified models,
+ * and set the model recursiveness to this level. setting it to false
+ * disables this feature. DEFAULTS TO: true
+ *
+ * - notices: (boolean, optional) issues E_NOTICES for bindings referenced in a
+ * containable call that are not valid. DEFAULTS TO: false
+ *
+ * - autoFields: (boolean, optional) auto-add needed fields to fetch requested
+ * bindings. DEFAULTS TO: true
+ *
+ * @param object $Model Model using the behavior
+ * @param array $settings Settings to override for model.
+ * @access public
+ */
+ function setup(&$Model, $settings = array()) {
+ if (!isset($this->settings[$Model->alias])) {
+ $this->settings[$Model->alias] = array('recursive' => true, 'notices' => true, 'autoFields' => true);
+ }
+ $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], ife(is_array($settings), $settings, array()));
+ }
+/**
+ * Runs before a find() operation. Used to allow 'contain' setting
+ * as part of the find call, like this:
+ *
+ * Model->find('all', array('contain' => array('Model1', 'Model2')));
+ *
+ * Model->find('all', array('contain' => array(
+ * 'Model1' => array('Model11', 'Model12'),
+ * 'Model2',
+ * 'Model3' => array(
+ * 'Model31' => 'Model311',
+ * 'Model32',
+ * 'Model33' => array('Model331', 'Model332')
+ * )));
+ *
+ * @param object $Model Model using the behavior
+ * @param array $query Query parameters as set by cake
+ * @access public
+ */
+ function beforeFind(&$Model, $query) {
+ $reset = (isset($query['reset']) ? $query['reset'] : true);
+ $noContain = ((isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || (isset($query['contain']) && empty($query['contain'])));
+ $contain = array();
+ if (isset($this->runtime[$Model->alias]['contain'])) {
+ $contain = $this->runtime[$Model->alias]['contain'];
+ unset($this->runtime[$Model->alias]['contain']);
+ }
+ if (isset($query['contain'])) {
+ $contain = array_merge($contain, (array)$query['contain']);
+ }
+ if ($noContain || (!$contain && !isset($Model->__backOriginalAssociation)) || in_array($contain, array(null, false), true) || (isset($contain[0]) && $contain[0] === null)) {
+ if ($noContain) {
+ $query['recursive'] = -1;
+ }
+ return $query;
+ }
+ if ((isset($contain[0]) && is_bool($contain[0])) || is_bool(end($contain))) {
+ $reset = is_bool(end($contain))
+ ? array_pop($contain)
+ : array_shift($contain);
+ }
+ $containments = $this->containments($Model, $contain);
+ $map = $this->containmentsMap($containments);
+
+ $mandatory = array();
+ foreach ($containments['models'] as $name => $model) {
+ $instance =& $model['instance'];
+ $needed = $this->fieldDependencies($instance, $map, false);
+ if (!empty($needed)) {
+ $mandatory = array_merge($mandatory, $needed);
+ }
+ if ($contain) {
+ $backupBindings = array();
+ foreach($this->types as $relation) {
+ $backupBindings[$relation] = $instance->{$relation};
+ }
+ foreach ($this->types as $type) {
+ $unbind = array();
+ foreach ($instance->{$type} as $assoc => $options) {
+ if (!isset($model['keep'][$assoc])) {
+ $unbind[] = $assoc;
+ }
+ if (isset($model['keep'][$assoc]) && !empty($model['keep'][$assoc])) {
+ if (isset($model['keep'][$assoc]['fields'])) {
+ $model['keep'][$assoc]['fields'] = $this->fieldDependencies($containments['models'][$assoc]['instance'], $map, $model['keep'][$assoc]['fields']);
+ }
+ if (!$reset && empty($instance->__backOriginalAssociation)) {
+ $instance->__backOriginalAssociation = $backupBindings;
+ } else if ($reset) {
+ $instance->__backAssociation[$type] = $instance->{$type};
+ }
+ $instance->{$type}[$assoc] = array_merge($instance->{$type}[$assoc], $model['keep'][$assoc]);
+ }
+ if (!$reset) {
+ $instance->__backInnerAssociation[] = $assoc;
+ }
+ }
+ if ($unbind) {
+ if (!$reset && empty($instance->__backOriginalAssociation)) {
+ $instance->__backOriginalAssociation = $backupBindings;
+ }
+ $instance->unbindModel(array($type => $unbind), $reset);
+ }
+ }
+ }
+ }
+
+ if ($this->settings[$Model->alias]['recursive']) {
+ $query['recursive'] = (isset($query['recursive'])) ? $query['recursive'] : $containments['depth'];
+ }
+
+ $autoFields = ($this->settings[$Model->alias]['autoFields']
+ && !in_array($Model->findQueryType, array('list', 'count'))
+ && !empty($query['fields']));
+ if (!$autoFields) {
+ return $query;
+ }
+
+ $query['fields'] = (array)$query['fields'];
+ if (!empty($Model->belongsTo)) {
+ foreach($Model->belongsTo as $assoc => $data) {
+ if (!empty($data['fields'])) {
+ foreach((array) $data['fields'] as $field) {
+ $query['fields'][] = (strpos($field, '.') === false ? $assoc . '.' : '') . $field;
+ }
+ }
+ }
+ }
+ if (!empty($mandatory[$Model->alias])) {
+ foreach($mandatory[$Model->alias] as $field) {
+ if ($field == '--primaryKey--') {
+ $field = $Model->primaryKey;
+ } else if (preg_match('/^.+\.\-\-[^-]+\-\-$/', $field)) {
+ list($modelName, $field) = explode('.', $field);
+ $field = $modelName . '.' . (($field === '--primaryKey--') ? $Model->$modelName->primaryKey : $field);
+ }
+ $query['fields'][] = $field;
+ }
+ }
+ $query['fields'] = array_unique($query['fields']);
+ return $query;
+ }
+/**
+ * Unbinds all relations from a model except the specified ones. Calling this function without
+ * parameters unbinds all related models.
+ *
+ * @param object $Model Model on which binding restriction is being applied
+ * @access public
+ */
+ function contain(&$Model) {
+ $args = func_get_args();
+ $contain = call_user_func_array('am', array_slice($args, 1));
+ $this->runtime[$Model->alias]['contain'] = $contain;
+ }
+/**
+ * Permanently restore the original binding settings of given model, useful
+ * for restoring the bindings after using 'reset' => false as part of the
+ * contain call.
+ *
+ * @param object $Model Model on which to reset bindings
+ * @access public
+ */
+ function resetBindings(&$Model) {
+ if (!empty($Model->__backOriginalAssociation)) {
+ $Model->__backAssociation = $Model->__backOriginalAssociation;
+ unset($Model->__backOriginalAssociation);
+ }
+ $Model->resetAssociations();
+ if (!empty($Model->__backInnerAssociation)) {
+ $assocs = $Model->__backInnerAssociation;
+ unset($Model->__backInnerAssociation);
+ foreach($assocs as $currentModel) {
+ $this->resetBindings($Model->$currentModel);
+ }
+ }
+ }
+/**
+ * Process containments for model.
+ *
+ * @param object $Model Model on which binding restriction is being applied
+ * @param array $contain Parameters to use for restricting this model
+ * @param array $containments Current set of containments
+ * @param bool $throwErrors Wether unexisting bindings show throw errors
+ * @return array Containments
+ * @access public
+ */
+ function containments(&$Model, $contain, $containments = array(), $throwErrors = null) {
+ $options = array('className', 'joinTable', 'with', 'foreignKey', 'associationForeignKey', 'conditions', 'fields', 'order', 'limit', 'offset', 'unique', 'finderQuery', 'deleteQuery', 'insertQuery');
+ $keep = array();
+ $depth = array();
+ if ($throwErrors === null) {
+ $throwErrors = (empty($this->settings[$Model->alias]) ? true : $this->settings[$Model->alias]['notices']);
+ }
+ foreach ((array)$contain as $name => $children) {
+ if (is_numeric($name)) {
+ $name = $children;
+ $children = array();
+ }
+ if (preg_match('/(? $children);
+ }
+
+ $children = (array)$children;
+ foreach ($children as $key => $val) {
+ if (is_string($key) && is_string($val) && !in_array($key, $options, true)) {
+ $children[$key] = (array)$val;
+ }
+ }
+ $keys = array_keys($children);
+ if ($keys && isset($children[0])) {
+ $keys = array_values($children);
+ }
+ foreach ($keys as $i => $key) {
+ if (is_array($key)) {
+ continue;
+ }
+ $optionKey = in_array($key, $options, true);
+ if (!$optionKey && is_string($key) && preg_match('/^[a-z(]/', $key) && (!isset($Model->{$key}) || !is_object($Model->{$key}))) {
+ $option = 'fields';
+ $val = array($key);
+ if ($key{0} == '(') {
+ $val = preg_split('/\s?,/', substr(substr($key, 1), 0, -1));
+ } elseif (preg_match('/ASC|DESC$/', $key)) {
+ $option = 'order';
+ $val = $Model->{$name}->alias.'.'.$key;
+ } elseif (preg_match('/[ =!]/', $key)) {
+ $option = 'conditions';
+ $val = $Model->{$name}->alias.'.'.$key;
+ }
+ $children[$option] = isset($children[$option]) ? array_merge((array) $children[$option], (array) $val) : $val;
+ unset($children[$key], $children[$i]);
+ $key = $option;
+ $optionKey = true;
+ }
+ if ($optionKey) {
+ $keep[$name][$key] = array_merge((isset($keep[$name][$key]) ? $keep[$name][$key] : array()), (array) $children[$key]);
+ unset($children[$key]);
+ }
+ }
+
+ if ($throwErrors && (!isset($Model->{$name}) || !is_object($Model->{$name}))) {
+ trigger_error(__(sprintf('Model "%s" is not associated with model "%s"', $Model->alias, $name), true), E_USER_WARNING);
+ continue;
+ }
+
+ $containments = $this->containments($Model->{$name}, $children, $containments);
+ $depths[] = $containments['depth'] + 1;
+ if (!isset($keep[$name])) {
+ $keep[$name] = array();
+ }
+ }
+
+ if (!isset($containments['models'][$Model->alias])) {
+ $containments['models'][$Model->alias] = array('keep' => array(),'instance' => &$Model);
+ }
+
+ $containments['models'][$Model->alias]['keep'] = array_merge($containments['models'][$Model->alias]['keep'], $keep);
+ $containments['depth'] = empty($depths) ? 0 : max($depths);
+ return $containments;
+ }
+/**
+ * Calculate needed fields to fetch the required bindings for the given model.
+ *
+ * @param object $Model Model
+ * @param array $map Map of relations for given model
+ * @param mixed $fields If array, fields to initially load, if false use $Model as primary model
+ * @return array Fields
+ * @access public
+ */
+ function fieldDependencies(&$Model, $map, $fields = array()) {
+ if ($fields === false) {
+ foreach($map as $parent => $children) {
+ foreach($children as $type => $bindings) {
+ foreach($bindings as $dependency) {
+ switch($type) {
+ case 'belongsTo':
+ $fields[$parent][] = $dependency . '.--primaryKey--';
+ break;
+ case 'hasAndBelongsToMany':
+ $fields[$parent][] = '--primaryKey--';
+ $fields[$dependency][] = '--primaryKey--';
+ break;
+ }
+ }
+ }
+ }
+ return $fields;
+ }
+ if (empty($map[$Model->alias])) {
+ return $fields;
+ }
+ foreach($map[$Model->alias] as $type => $bindings) {
+ foreach($bindings as $dependency) {
+ $innerFields = array();
+ switch($type) {
+ case 'belongsTo':
+ $fields[] = $Model->{$type}[$dependency]['foreignKey'];
+ break;
+ case 'hasOne':
+ case 'hasMany':
+ $innerFields[] = $Model->$dependency->primaryKey;
+ $fields[] = $Model->primaryKey;
+ break;
+ }
+ if (!empty($innerFields) && !empty($Model->{$type}[$dependency]['fields'])) {
+ $Model->{$type}[$dependency]['fields'] = array_unique(array_merge($Model->{$type}[$dependency]['fields'], $innerFields));
+ }
+ }
+ }
+ return array_unique($fields);
+ }
+/**
+ * Build the map of containments
+ *
+ * @param array $containments Containments
+ * @return array Built containments
+ * @access public
+ */
+ function containmentsMap($containments) {
+ $map = array();
+ foreach ($containments['models'] as $name => $model) {
+ $instance =& $model['instance'];
+ foreach ($this->types as $type) {
+ foreach ($instance->{$type} as $assoc => $options) {
+ if (isset($model['keep'][$assoc])) {
+ $map[$name][$type] = isset($map[$name][$type]) ? array_merge($map[$name][$type], (array)$assoc) : (array)$assoc;
+ }
+ }
+ }
+ }
+ return $map;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/cake/tests/cases/libs/model/behaviors/containable.test.php b/cake/tests/cases/libs/model/behaviors/containable.test.php
new file mode 100644
index 000000000..627defc63
--- /dev/null
+++ b/cake/tests/cases/libs/model/behaviors/containable.test.php
@@ -0,0 +1,2968 @@
+
+ * Copyright 2005-2008, Cake Software Foundation, Inc.
+ * 1785 E. Sahara Avenue, Suite 490-204
+ * Las Vegas, Nevada 89104
+ *
+ * Licensed under The Open Group Test Suite License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @filesource
+ * @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
+ * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
+ * @package cake.tests
+ * @subpackage cake.tests.cases.libs.model.behaviors
+ * @since CakePHP(tm) v 1.2.0.5669
+ * @version $Revision$
+ * @modifiedby $LastChangedBy$
+ * @lastmodified $Date$
+ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
+ */
+
+App::import('Core', array('AppModel', 'Model'));
+require_once(dirname(__FILE__) . DS . '..' . DS . 'models.php');
+
+class ContainableTest extends CakeTestCase {
+/**
+ * Fixtures associated with this test case
+ *
+ * @var array
+ * @access public
+ */
+ var $fixtures = array(
+ 'core.article', 'core.article_featured', 'core.article_featureds_tags', 'core.articles_tag', 'core.attachment', 'core.category',
+ 'core.comment', 'core.featured', 'core.tag', 'core.user'
+ );
+/**
+ * Method executed before each test
+ *
+ * @access public
+ */
+ function startTest() {
+ $this->User =& ClassRegistry::init('User');
+ $this->Article =& ClassRegistry::init('Article');
+
+ $this->User->bind(array(
+ 'Article' => array('type' => 'hasMany'),
+ 'ArticleFeatured' => array('type' => 'hasMany'),
+ 'Comment' => array('type' => 'hasMany')
+ ));
+ $this->User->ArticleFeatured->unbindModel(array('belongsTo' => array('Category')), false);
+ $this->User->ArticleFeatured->hasMany['Comment']['foreignKey'] = 'article_id';
+
+ $this->User->Behaviors->attach('Containable');
+ $this->Article->Behaviors->attach('Containable');
+ }
+/**
+ * Method executed after each test
+ *
+ * @access public
+ */
+ function endTest() {
+ unset($this->Article);
+ unset($this->User);
+
+ ClassRegistry::flush();
+ }
+
+ function testContainments() {
+ $r = $this->__containments($this->Article, array('Comment' => array('conditions' => array('Comment.user_id' => 2))));
+ $this->assertTrue(Set::matches('/Article/keep/Comment/conditions[Comment.user_id=2]', $r));
+
+ $r = $this->__containments($this->User, array(
+ 'ArticleFeatured' => array(
+ 'Featured' => array(
+ 'id',
+ 'Category' => 'name'
+ )
+ )));
+ $this->assertEqual(Set::extract('/ArticleFeatured/keep/Featured/fields', $r), array('id'));
+ }
+
+ function testBeforeFind() {
+ $r = $this->Article->find('all', array('contain' => array('Comment')));
+ $this->assertFalse(Set::matches('/User', $r));
+ $this->assertTrue(Set::matches('/Comment', $r));
+ $this->assertFalse(Set::matches('/Comment/User', $r));
+
+ $r = $this->Article->find('all', array('contain' => 'Comment.User'));
+ $this->assertTrue(Set::matches('/Comment/User', $r));
+ $this->assertFalse(Set::matches('/Comment/Article', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('Comment' => array('User', 'Article'))));
+ $this->assertTrue(Set::matches('/Comment/User', $r));
+ $this->assertTrue(Set::matches('/Comment/Article', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('Comment' => array('conditions' => array('Comment.user_id' => 2)))));
+ $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('Comment.user_id = 2')));
+ $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
+
+ $r = $this->Article->find('all', array('contain' => 'Comment.id DESC'));
+ $ids = $descIds = Set::extract('/Comment[1]/id', $r);
+ rsort($descIds);
+ $this->assertEqual($ids, $descIds);
+
+ $r = $this->Article->find('all', array('contain' => 'Comment'));
+ $this->assertTrue(Set::matches('/Comment[user_id!=2]', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => 'comment'))));
+ $this->assertFalse(Set::matches('/Comment/created', $r));
+ $this->assertTrue(Set::matches('/Comment/comment', $r));
+ $this->assertFalse(Set::matches('/Comment/updated', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => array('comment', 'updated')))));
+ $this->assertFalse(Set::matches('/Comment/created', $r));
+ $this->assertTrue(Set::matches('/Comment/comment', $r));
+ $this->assertTrue(Set::matches('/Comment/updated', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('Comment' => array('comment', 'updated'))));
+ $this->assertFalse(Set::matches('/Comment/created', $r));
+ $this->assertTrue(Set::matches('/Comment/comment', $r));
+ $this->assertTrue(Set::matches('/Comment/updated', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('Comment(comment,updated)')));
+ $this->assertFalse(Set::matches('/Comment/created', $r));
+ $this->assertTrue(Set::matches('/Comment/comment', $r));
+ $this->assertTrue(Set::matches('/Comment/updated', $r));
+
+ $r = $this->Article->find('all', array('contain' => 'Comment.created'));
+ $this->assertTrue(Set::matches('/Comment/created', $r));
+ $this->assertFalse(Set::matches('/Comment/comment', $r));
+
+ $r = $this->Article->find('all', array('contain' => array('User.Article(title)', 'Comment(comment)')));
+ $this->assertFalse(Set::matches('/Comment/Article', $r));
+ $this->assertFalse(Set::matches('/Comment/User', $r));
+ $this->assertTrue(Set::matches('/Comment/comment', $r));
+ $this->assertFalse(Set::matches('/Comment/created', $r));
+ $this->assertTrue(Set::matches('/User/Article/title', $r));
+ $this->assertFalse(Set::matches('/User/Article/created', $r));
+
+ $r = $this->Article->find('all', array('contain' => array()));
+ $this->assertFalse(Set::matches('/User', $r));
+ $this->assertFalse(Set::matches('/Comment', $r));
+
+ $this->expectError();
+ $r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
+ }
+
+ function testContain() {
+ $this->Article->contain('Comment.User');
+ $r = $this->Article->find('all');
+ $this->assertTrue(Set::matches('/Comment/User', $r));
+ $this->assertFalse(Set::matches('/Comment/Article', $r));
+
+ $r = $this->Article->find('all');
+ $this->assertFalse(Set::matches('/Comment/User', $r));
+ }
+
+ function testFindEmbeddedNoBindings() {
+ $result = $this->Article->find('all', array('contain' => false));
+ $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->assertEqual($result, $expected);
+ }
+
+ function testFindFirstLevel() {
+ $this->Article->contain('User');
+ $result = $this->Article->find('all', array('recursive' => 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'
+ )
+ ),
+ 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'
+ )
+ ),
+ 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'
+ )
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->Article->contain('User', 'Comment');
+ $result = $this->Article->find('all', array('recursive' => 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'
+ )
+ )
+ ),
+ 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'
+ )
+ )
+ ),
+ 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()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testFindEmbeddedFirstLevel() {
+ $result = $this->Article->find('all', array('contain' => array('User')));
+ $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'
+ )
+ ),
+ 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'
+ )
+ ),
+ 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'
+ )
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('all', array('contain' => array('User', 'Comment')));
+ $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'
+ )
+ )
+ ),
+ 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'
+ )
+ )
+ ),
+ 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()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testFindSecondLevel() {
+ $this->Article->contain(array('Comment' => 'User'));
+ $result = $this->Article->find('all', array('recursive' => 2));
+ $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'
+ ),
+ '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',
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20: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',
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24: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',
+ 'User' => array(
+ 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18: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',
+ 'User' => array(
+ 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18: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'
+ ),
+ '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',
+ 'User' => array(
+ 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18: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',
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20: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'
+ ),
+ 'Comment' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->Article->contain(array('User' => 'ArticleFeatured'));
+ $result = $this->Article->find('all', array('recursive' => 2));
+ $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',
+ 'ArticleFeatured' => 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(
+ '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',
+ 'ArticleFeatured' => 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(
+ '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',
+ 'ArticleFeatured' => 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->assertEqual($result, $expected);
+
+ $this->Article->contain(array('User' => array('ArticleFeatured', 'Comment')));
+ $result = $this->Article->find('all', array('recursive' => 2));
+ $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',
+ 'ArticleFeatured' => 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'
+ )
+ ),
+ '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(
+ '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',
+ 'ArticleFeatured' => 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'
+ )
+ ),
+ 'Comment' => array()
+ )
+ ),
+ 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',
+ 'ArticleFeatured' => 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'
+ )
+ ),
+ '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'
+ )
+ )
+ )
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->Article->contain(array('User' => array('ArticleFeatured')), 'Tag', array('Comment' => 'Attachment'));
+ $result = $this->Article->find('all', array('recursive' => 2));
+ $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',
+ 'ArticleFeatured' => 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'
+ )
+ )
+ ),
+ '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',
+ 'Attachment' => 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',
+ 'Attachment' => 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',
+ 'Attachment' => array()
+ ),
+ 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',
+ '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' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26: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'
+ ),
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
+ 'ArticleFeatured' => 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'
+ )
+ )
+ ),
+ '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',
+ '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',
+ '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')
+ )
+ ),
+ 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',
+ 'ArticleFeatured' => 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'
+ )
+ )
+ ),
+ 'Comment' => array(),
+ 'Tag' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testFindEmbeddedSecondLevel() {
+ $result = $this->Article->find('all', array('contain' => array('Comment' => 'User')));
+ $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'
+ ),
+ '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',
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20: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',
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24: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',
+ 'User' => array(
+ 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18: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',
+ 'User' => array(
+ 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18: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'
+ ),
+ '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',
+ 'User' => array(
+ 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18: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',
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20: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'
+ ),
+ 'Comment' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured')));
+ $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',
+ 'ArticleFeatured' => 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(
+ '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',
+ 'ArticleFeatured' => 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(
+ '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',
+ 'ArticleFeatured' => 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->assertEqual($result, $expected);
+
+ $result = $this->Article->find('all', array('contain' => array('User' => array('ArticleFeatured', 'Comment'))));
+ $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',
+ 'ArticleFeatured' => 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'
+ )
+ ),
+ '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(
+ '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',
+ 'ArticleFeatured' => 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'
+ )
+ ),
+ 'Comment' => array()
+ )
+ ),
+ 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',
+ 'ArticleFeatured' => 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'
+ )
+ ),
+ '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'
+ )
+ )
+ )
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured', 'Tag', 'Comment' => 'Attachment')));
+ $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',
+ 'ArticleFeatured' => 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'
+ )
+ )
+ ),
+ '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',
+ 'Attachment' => 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',
+ 'Attachment' => 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',
+ 'Attachment' => array()
+ ),
+ 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',
+ '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' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26: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'
+ ),
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
+ 'ArticleFeatured' => 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'
+ )
+ )
+ ),
+ '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',
+ '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',
+ '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')
+ )
+ ),
+ 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',
+ 'ArticleFeatured' => 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'
+ )
+ )
+ ),
+ 'Comment' => array(),
+ 'Tag' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testFindThirdLevel() {
+ $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category')));
+ $result = $this->User->find('all', array('recursive' => 3));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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(
+ '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',
+ 'Featured' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
+ $result = $this->User->find('all', array('recursive' => 3));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ ),
+ 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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'
+ ),
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
+ $result = $this->User->find('all', array('recursive' => 3));
+ $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'
+ ),
+ '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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ 'Attachment' => 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',
+ 'Attachment' => 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',
+ 'Attachment' => array()
+ ),
+ 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',
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22: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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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',
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testFindEmbeddedThirdLevel() {
+ $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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(
+ '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',
+ 'Featured' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ ),
+ 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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'
+ ),
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
+ $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'
+ ),
+ '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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ 'Attachment' => 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',
+ 'Attachment' => 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',
+ 'Attachment' => array()
+ ),
+ 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',
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22: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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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',
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testSettingsThirdLevel() {
+ $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => array('Category' => array('id', 'name'))))));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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, 'name' => 'Category 1'
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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, 'name' => 'Category 1'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $r = $this->User->find('all', array('contain' => array(
+ 'ArticleFeatured' => array(
+ 'id', 'title',
+ 'Featured' => array(
+ 'id', 'category_id',
+ 'Category' => array('id', 'name')
+ )
+ )
+ )));
+
+ $this->assertTrue(Set::matches('/User[id=1]', $r));
+ $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured', $r));
+ $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
+ $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[id=1]', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
+
+ $r = $this->User->find('all', array('contain' => array(
+ 'ArticleFeatured' => array(
+ 'title',
+ 'Featured' => array(
+ 'id',
+ 'Category' => 'name'
+ )
+ )
+ )));
+
+ $this->assertTrue(Set::matches('/User[id=1]', $r));
+ $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured', $r));
+ $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
+ $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
+ $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
+
+ $result = $this->User->find('all', array('contain' => array(
+ 'ArticleFeatured' => array(
+ 'title',
+ 'Featured' => array(
+ 'category_id',
+ 'Category' => 'name'
+ )
+ )
+ )));
+ $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'
+ ),
+ 'ArticleFeatured' => array(
+ array(
+ 'title' => 'First Article', 'id' => 1, 'user_id' => 1,
+ 'Featured' => array(
+ 'category_id' => 1, 'id' => 1,
+ 'Category' => array(
+ 'name' => 'Category 1'
+ )
+ )
+ ),
+ array(
+ 'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
+ 'Featured' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => array(
+ array(
+ 'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
+ 'Featured' => array(
+ 'category_id' => 1, 'id' => 2,
+ 'Category' => array(
+ 'name' => 'Category 1'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->User->find('all', array('contain' => array(
+ 'ArticleFeatured' => array(
+ 'title', 'order' => 'title DESC',
+ 'Featured' => array(
+ 'category_id',
+ 'Category' => 'name'
+ )
+ )
+ )));
+ $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'
+ ),
+ 'ArticleFeatured' => array(
+ array(
+ 'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
+ 'Featured' => array()
+ ),
+ array(
+ 'title' => 'First Article', 'id' => 1, 'user_id' => 1,
+ 'Featured' => array(
+ 'category_id' => 1, 'id' => 1,
+ 'Category' => array(
+ 'name' => 'Category 1'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => array(
+ array(
+ 'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
+ 'Featured' => array(
+ 'category_id' => 1, 'id' => 2,
+ 'Category' => array(
+ 'name' => 'Category 1'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testFindThirdLevelNonReset() {
+ $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category')));
+ $result = $this->User->find('all', array('recursive' => 3));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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(
+ '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',
+ 'Featured' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->User->resetBindings();
+
+ $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
+ $result = $this->User->find('all', array('recursive' => 3));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ ),
+ 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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'
+ ),
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->User->resetBindings();
+
+ $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
+ $result = $this->User->find('all', array('recursive' => 3));
+ $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'
+ ),
+ '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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ 'Attachment' => 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',
+ 'Attachment' => 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',
+ 'Attachment' => array()
+ ),
+ 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',
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22: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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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',
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testFindEmbeddedThirdLevelNonReset() {
+ $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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(
+ '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',
+ 'Featured' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
+ $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
+
+ $this->User->resetBindings();
+
+ $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
+ $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
+ $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
+
+ $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ ),
+ 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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'
+ ),
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
+ $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
+ $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
+
+ $this->User->resetBindings();
+ $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
+ $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
+ $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
+
+ $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')), false)));
+ $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'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ ),
+ 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',
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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'
+ ),
+ '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'
+ ),
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
+ $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
+ $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
+
+ $this->User->resetBindings();
+ $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
+ $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
+ $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
+
+ $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
+ $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'
+ ),
+ '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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ 'Attachment' => 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',
+ 'Attachment' => 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',
+ 'Attachment' => array()
+ ),
+ 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',
+ 'Attachment' => array()
+ )
+ )
+ ),
+ 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',
+ 'Featured' => array(),
+ 'Comment' => array()
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ ),
+ array(
+ 'User' => array(
+ 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22: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'
+ )
+ ),
+ 'ArticleFeatured' => 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',
+ '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'
+ )
+ ),
+ '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',
+ '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',
+ 'Attachment' => array()
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'User' => array(
+ 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
+ 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
+ ),
+ 'Article' => array(),
+ 'ArticleFeatured' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured')));
+ $this->__assertBindings($this->User->Article);
+ $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
+ $this->__assertBindings($this->User->ArticleFeatured->Comment, array('hasOne' => array('Attachment')));
+
+ $this->User->resetBindings();
+ $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
+ $this->__assertBindings($this->User->Article, array('belongsTo' => array('User'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
+ $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
+ $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
+ $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
+ }
+
+ function testFindConditionalBinding() {
+ $this->Article->contain(array('User(user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created' => '>= 2007-03-18 12:24'))));
+ $result = $this->Article->find('all', array('fields' => array('title')));
+ $expected = array(
+ array(
+ 'Article' => array('id' => 1, 'title' => 'First Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
+ ),
+ array(
+ 'Article' => array('id' => 2, 'title' => 'Second Article'),
+ 'User' => array('id' => 3, 'user' => 'larry'),
+ 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
+ ),
+ array(
+ 'Article' => array('id' => 3, 'title' => 'Third Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
+ $result = $this->Article->find('all', array('fields' => array('title')));
+ $expected = array(
+ array(
+ 'Article' => array('id' => 1, 'title' => 'First Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array(
+ array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
+ array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
+ )
+ ),
+ array(
+ 'Article' => array('id' => 2, 'title' => 'Second Article'),
+ 'User' => array('id' => 3, 'user' => 'larry'),
+ 'Tag' => array(
+ array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
+ array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
+ )
+ ),
+ array(
+ 'Article' => array('id' => 3, 'title' => 'Third Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('all', array(
+ 'fields' => array('title'),
+ 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created')))
+ ));
+ $expected = array(
+ array(
+ 'Article' => array('id' => 1, 'title' => 'First Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array(
+ array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
+ array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
+ )
+ ),
+ array(
+ 'Article' => array('id' => 2, 'title' => 'Second Article'),
+ 'User' => array('id' => 3, 'user' => 'larry'),
+ 'Tag' => array(
+ array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
+ array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
+ )
+ ),
+ array(
+ 'Article' => array('id' => 3, 'title' => 'Third Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created' => '>= 2007-03-18 12:24'))));
+ $result = $this->Article->find('all', array('fields' => array('title')));
+ $expected = array(
+ array(
+ 'Article' => array('id' => 1, 'title' => 'First Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
+ ),
+ array(
+ 'Article' => array('id' => 2, 'title' => 'Second Article'),
+ 'User' => array('id' => 3, 'user' => 'larry'),
+ 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
+ ),
+ array(
+ 'Article' => array('id' => 3, 'title' => 'Third Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array()
+ )
+ );
+ $this->assertEqual($result, $expected);
+ }
+
+ function testOtherFinds() {
+ $result = $this->Article->find('count');
+ $expected = 3;
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('count', array('conditions' => array('Article.id' => '> 1')));
+ $expected = 2;
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('count', array('contain' => array()));
+ $expected = 3;
+ $this->assertEqual($result, $expected);
+
+ $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created' => '>= 2007-03-18 12:24'))));
+ $result = $this->Article->find('first', array('fields' => array('title')));
+ $expected = array(
+ 'Article' => array('id' => 1, 'title' => 'First Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
+ );
+ $this->assertEqual($result, $expected);
+
+ $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
+ $result = $this->Article->find('first', array('fields' => array('title')));
+ $expected = array(
+ 'Article' => array('id' => 1, 'title' => 'First Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array(
+ array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
+ array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
+ )
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('first', array(
+ 'fields' => array('title'),
+ 'order' => 'Article.id DESC',
+ 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created')))
+ ));
+ $expected = array(
+ 'Article' => array('id' => 3, 'title' => 'Third Article'),
+ 'User' => array('id' => 1, 'user' => 'mariano'),
+ 'Tag' => array()
+ );
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Article->find('list', array(
+ 'contain' => array('User(id,user)'),
+ 'fields' => array('Article.id', 'Article.title')
+ ));
+ $expected = array(
+ 1 => 'First Article',
+ 2 => 'Second Article',
+ 3 => 'Third Article'
+ );
+ $this->assertEqual($result, $expected);
+
+ $Controller =& new Controller();
+ $Controller->uses = array('Article');
+ $Controller->passedArgs[] = '1';
+ $Controller->params['url'] = array();
+ $Controller->constructClasses();
+ $Controller->paginate = array('Article' => array('fields' => array('title')));
+ $Controller->Article->contain(false, array('User(user)'));
+ $result = $Controller->paginate('Article');
+ $Controller->Article->resetBindings();
+ $expected = array(
+ array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano')),
+ array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry')),
+ array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano')),
+ );
+ $this->assertEqual($result, $expected);
+
+ $r = $Controller->Article->find('all');
+ $this->assertTrue(Set::matches('/Article[id=1]', $r));
+ $this->assertTrue(Set::matches('/User[id=1]', $r));
+ $this->assertTrue(Set::matches('/Tag[id=1]', $r));
+ }
+
+ function __containments(&$Model, $contain = array()) {
+ if (!is_array($Model)) {
+ $result = $Model->containments($contain);
+ return $this->__containments($result['models']);
+ } else {
+ $result = $Model;
+ foreach($result as $i => $containment) {
+ $result[$i] = array_diff_key($containment, array('instance' => true));
+ }
+ }
+
+ return $result;
+ }
+
+ function __assertBindings(&$Model, $expected = array()) {
+ $expected = array_merge(array('belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array()), $expected);
+
+ foreach($expected as $binding => $expect) {
+ $this->assertEqual(array_keys($Model->$binding), $expect);
+ }
+ }
+
+ function __bindings(&$Model, $extra = array(), $output = true) {
+ $relationTypes = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
+
+ $debug = '[';
+ $lines = array();
+ foreach($relationTypes as $binding) {
+ if (!empty($Model->$binding)) {
+ $models = array_keys($Model->$binding);
+ foreach($models as $linkedModel) {
+ $line = $linkedModel;
+ if (!empty($extra) && !empty($Model->{$binding}[$linkedModel])) {
+ $extraData = array();
+ foreach(array_intersect_key($Model->{$binding}[$linkedModel], array_flip($extra)) as $key => $value) {
+ $extraData[] = $key . ': ' . (is_array($value) ? '(' . implode(', ', $value) . ')' : $value);
+ }
+ $line .= ' {' . implode(' - ', $extraData) . '}';
+ }
+ $lines[] = $line;
+ }
+ }
+ }
+ $debug .= implode(' | ' , $lines);
+ $debug .= ']';
+ $debug = '' . $Model->alias . ': ' . $debug . '
';
+
+ if ($output) {
+ echo $debug;
+ }
+
+ return $debug;
+ }
+}
+
+?>
\ No newline at end of file