Fixing bug for related records not being returned when using $recursive > 1.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5902 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-10-26 08:40:10 +00:00
parent 28d6ef1688
commit 8d6599c34b
19 changed files with 492 additions and 359 deletions

View file

@ -94,7 +94,7 @@ class ModelEngine extends CacheEngine {
return false; return false;
} }
$cache = array($this->__Model->name => array( $cache = array($this->__Model->currentModel => array(
$this->__fields[0] => $data, $this->__fields[0] => $data,
$this->__fields[1] => time() + $duration)); $this->__fields[1] => time() + $duration));

View file

@ -297,14 +297,14 @@ class DB_ACL extends AclBase {
$inherited = array(); $inherited = array();
for ($i = 0 ; $i < count($aroPath); $i++) { for ($i = 0 ; $i < count($aroPath); $i++) {
$perms = $this->Aro->Permission->findAll(array( $perms = $this->Aro->Permission->findAll(array(
$this->Aro->Permission->name . '.aro_id' => $aroPath[$i][$this->Aro->name]['id'], $this->Aro->Permission->currentModel . '.aro_id' => $aroPath[$i][$this->Aro->currentModel]['id'],
$this->Aro->Permission->name . '.aco_id' => $acoPath->extract('{n}.' . $this->Aco->name . '.id')), $this->Aro->Permission->currentModel . '.aco_id' => $acoPath->extract('{n}.' . $this->Aco->currentModel . '.id')),
null, array($this->Aco->name . '.lft' => 'desc'), null, null, 0); null, array($this->Aco->currentModel . '.lft' => 'desc'), null, null, 0);
if (empty($perms)) { if (empty($perms)) {
continue; continue;
} else { } else {
foreach (Set::extract($perms, '{n}.' . $this->Aro->Permission->name) as $perm) { foreach (Set::extract($perms, '{n}.' . $this->Aro->Permission->currentModel) as $perm) {
if ($action == '*') { if ($action == '*') {
foreach ($permKeys as $key) { foreach ($permKeys as $key) {
@ -358,7 +358,7 @@ class DB_ACL extends AclBase {
} }
if (isset($perms[0])) { if (isset($perms[0])) {
$save = $perms[0][$this->Aro->Permission->name]; $save = $perms[0][$this->Aro->Permission->currentModel];
} }
if ($actions == "*") { if ($actions == "*") {
@ -387,7 +387,7 @@ class DB_ACL extends AclBase {
$save['aco_id'] = $perms['aco']; $save['aco_id'] = $perms['aco'];
if ($perms['link'] != null && count($perms['link']) > 0) { if ($perms['link'] != null && count($perms['link']) > 0) {
$save['id'] = $perms['link'][0][$this->Aro->Permission->name]['id']; $save['id'] = $perms['link'][0][$this->Aro->Permission->currentModel]['id'];
} }
$this->Aro->Permission->create($save); $this->Aro->Permission->create($save);
return $this->Aro->Permission->save(); return $this->Aro->Permission->save();
@ -460,11 +460,11 @@ class DB_ACL extends AclBase {
} }
return array( return array(
'aro' => Set::extract($obj, 'Aro.0.'.$this->Aro->name.'.id'), 'aro' => Set::extract($obj, 'Aro.0.'.$this->Aro->currentModel.'.id'),
'aco' => Set::extract($obj, 'Aco.0.'.$this->Aco->name.'.id'), 'aco' => Set::extract($obj, 'Aco.0.'.$this->Aco->currentModel.'.id'),
'link' => $this->Aro->Permission->findAll(array( 'link' => $this->Aro->Permission->findAll(array(
$this->Aro->Permission->name . '.aro_id' => Set::extract($obj, 'Aro.0.'.$this->Aro->name.'.id'), $this->Aro->Permission->currentModel . '.aro_id' => Set::extract($obj, 'Aro.0.'.$this->Aro->currentModel.'.id'),
$this->Aro->Permission->name . '.aco_id' => Set::extract($obj, 'Aco.0.'.$this->Aco->name.'.id') $this->Aro->Permission->currentModel . '.aco_id' => Set::extract($obj, 'Aco.0.'.$this->Aco->currentModel.'.id')
)) ))
); );
} }

View file

@ -595,8 +595,8 @@ class Controller extends Object {
$errors = array(); $errors = array();
foreach ($objects as $object) { foreach ($objects as $object) {
$this->{$object->name}->set($object->data); $this->{$object->currentModel}->set($object->data);
$errors = array_merge($errors, $this->{$object->name}->invalidFields()); $errors = array_merge($errors, $this->{$object->currentModel}->invalidFields());
} }
return $this->validationErrors = (count($errors) ? $errors : false); return $this->validationErrors = (count($errors) ? $errors : false);
} }
@ -1098,8 +1098,8 @@ class Controller extends Object {
return array(); return array();
} }
$options = am($this->params, $this->params['url'], $this->passedArgs); $options = am($this->params, $this->params['url'], $this->passedArgs);
if (isset($this->paginate[$object->name])) { if (isset($this->paginate[$object->currentModel])) {
$defaults = $this->paginate[$object->name]; $defaults = $this->paginate[$object->currentModel];
} else { } else {
$defaults = $this->paginate; $defaults = $this->paginate;
} }
@ -1117,7 +1117,7 @@ class Controller extends Object {
if (!empty($options['order']) && is_array($options['order'])) { if (!empty($options['order']) && is_array($options['order'])) {
$key = key($options['order']); $key = key($options['order']);
if (strpos($key, '.') === false && $object->hasField($key)) { if (strpos($key, '.') === false && $object->hasField($key)) {
$options['order'][$object->name . '.' . $key] = $options['order'][$key]; $options['order'][$object->currentModel . '.' . $key] = $options['order'][$key];
unset($options['order'][$key]); unset($options['order'][$key]);
} }
} }
@ -1177,7 +1177,7 @@ class Controller extends Object {
'options' => $options 'options' => $options
); );
$this->params['paging'][$object->name] = $paging; $this->params['paging'][$object->currentModel] = $paging;
if (!in_array('Paginator', $this->helpers) && !array_key_exists('Paginator', $this->helpers)) { if (!in_array('Paginator', $this->helpers) && !array_key_exists('Paginator', $this->helpers)) {
$this->helpers[] = 'Paginator'; $this->helpers[] = 'Paginator';

View file

@ -52,8 +52,8 @@ class AclBehavior extends ModelBehavior {
if (is_string($config)) { if (is_string($config)) {
$config = array('type' => $config); $config = array('type' => $config);
} }
$this->settings[$model->name] = am(array('type' => 'requester'), $config); $this->settings[$model->currentModel] = am(array('type' => 'requester'), $config);
$type = $this->__typeMaps[$this->settings[$model->name]['type']]; $type = $this->__typeMaps[$this->settings[$model->currentModel]['type']];
if (!ClassRegistry::isKeySet($type)) { if (!ClassRegistry::isKeySet($type)) {
uses('model' . DS . 'db_acl'); uses('model' . DS . 'db_acl');
@ -63,7 +63,7 @@ class AclBehavior extends ModelBehavior {
} }
$model->{$type} =& $object; $model->{$type} =& $object;
if (!method_exists($model, 'parentNode')) { if (!method_exists($model, 'parentNode')) {
trigger_error("Callback parentNode() not defined in {$model->name}", E_USER_WARNING); trigger_error("Callback parentNode() not defined in {$model->currentModel}", E_USER_WARNING);
} }
} }
/** /**
@ -73,9 +73,9 @@ class AclBehavior extends ModelBehavior {
* @return array * @return array
*/ */
function node(&$model, $ref = null) { function node(&$model, $ref = null) {
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])]; $type = $this->__typeMaps[low($this->settings[$model->currentModel]['type'])];
if (empty($ref)) { if (empty($ref)) {
$ref = array('model' => $model->name, 'foreign_key' => $model->id); $ref = array('model' => $model->currentModel, 'foreign_key' => $model->id);
} }
return $model->{$type}->node($ref); return $model->{$type}->node($ref);
} }
@ -86,7 +86,7 @@ class AclBehavior extends ModelBehavior {
*/ */
function afterSave(&$model, $created) { function afterSave(&$model, $created) {
if ($created) { if ($created) {
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])]; $type = $this->__typeMaps[low($this->settings[$model->currentModel]['type'])];
$parent = $model->parentNode(); $parent = $model->parentNode();
if (!empty($parent)) { if (!empty($parent)) {
$parent = $this->node($model, $parent); $parent = $this->node($model, $parent);
@ -97,7 +97,7 @@ class AclBehavior extends ModelBehavior {
$model->{$type}->create(); $model->{$type}->create();
$model->{$type}->save(array( $model->{$type}->save(array(
'parent_id' => Set::extract($parent, "0.{$type}.id"), 'parent_id' => Set::extract($parent, "0.{$type}.id"),
'model' => $model->name, 'model' => $model->currentModel,
'foreign_key' => $model->id 'foreign_key' => $model->id
)); ));
} }
@ -107,7 +107,7 @@ class AclBehavior extends ModelBehavior {
* *
*/ */
function afterDelete(&$model) { function afterDelete(&$model) {
$type = $this->__typeMaps[low($this->settings[$model->name]['type'])]; $type = $this->__typeMaps[low($this->settings[$model->currentModel]['type'])];
$node = Set::extract($this->node($model), "0.{$type}.id"); $node = Set::extract($this->node($model), "0.{$type}.id");
if (!empty($node)) { if (!empty($node)) {
$model->{$type}->delete($node); $model->{$type}->delete($node);

View file

@ -55,12 +55,12 @@ class TranslateBehavior extends ModelBehavior {
function setup(&$model, $config = array()) { function setup(&$model, $config = array()) {
$db =& ConnectionManager::getDataSource($model->useDbConfig); $db =& ConnectionManager::getDataSource($model->useDbConfig);
if (!$db->connected) { if (!$db->connected) {
trigger_error('Datasource '.$model->useDbConfig.' for TranslateBehavior of model '.$model->name.' is not connected', E_USER_ERROR); trigger_error('Datasource '.$model->useDbConfig.' for TranslateBehavior of model '.$model->currentModel.' is not connected', E_USER_ERROR);
return false; return false;
} }
$this->settings[$model->name] = array(); $this->settings[$model->currentModel] = array();
$this->runtime[$model->name] = array('fields' => array()); $this->runtime[$model->currentModel] = array('fields' => array());
$this->translateModel($model); $this->translateModel($model);
return $this->bindTranslation($model, null, false); return $this->bindTranslation($model, null, false);
} }
@ -74,20 +74,20 @@ class TranslateBehavior extends ModelBehavior {
$RuntimeModel =& $this->translateModel($model); $RuntimeModel =& $this->translateModel($model);
if (is_string($query['fields']) && 'COUNT(*) AS '.$db->name('count') == $query['fields']) { if (is_string($query['fields']) && 'COUNT(*) AS '.$db->name('count') == $query['fields']) {
$this->runtime[$model->name]['count'] = true; $this->runtime[$model->currentModel]['count'] = true;
if (empty($locale)) { if (empty($locale)) {
return $query; return $query;
} }
$query['fields'] = 'COUNT(DISTINCT('.$db->name($model->name).'.'.$db->name($model->primaryKey).')) ' . $db->alias . 'count'; $query['fields'] = 'COUNT(DISTINCT('.$db->name($model->currentModel).'.'.$db->name($model->primaryKey).')) ' . $db->alias . 'count';
$query['joins'][] = array( $query['joins'][] = array(
'type' => 'INNER', 'type' => 'INNER',
'alias' => $RuntimeModel->name, 'alias' => $RuntimeModel->currentModel,
'table' => $db->name($tablePrefix . 'i18n'), 'table' => $db->name($tablePrefix . 'i18n'),
'conditions' => array( 'conditions' => array(
$model->name.'.id' => '{$__cakeIdentifier['.$RuntimeModel->name.'.foreign_key]__$}', $model->currentModel.'.id' => '{$__cakeIdentifier['.$RuntimeModel->currentModel.'.foreign_key]__$}',
$RuntimeModel->name.'.model' => $model->name, $RuntimeModel->currentModel.'.model' => $model->currentModel,
$RuntimeModel->name.'.locale' => $locale)); $RuntimeModel->currentModel.'.locale' => $locale));
return $query; return $query;
} }
@ -97,7 +97,7 @@ class TranslateBehavior extends ModelBehavior {
$autoFields = false; $autoFields = false;
if (empty($query['fields'])) { if (empty($query['fields'])) {
$query['fields'] = array($model->name.'.*'); $query['fields'] = array($model->currentModel.'.*');
foreach (array('hasOne', 'belongsTo') as $type) { foreach (array('hasOne', 'belongsTo') as $type) {
foreach ($model->{$type} as $key => $value) { foreach ($model->{$type} as $key => $value) {
@ -113,13 +113,13 @@ class TranslateBehavior extends ModelBehavior {
} }
$autoFields = true; $autoFields = true;
} }
$fields = am($this->settings[$model->name], $this->runtime[$model->name]['fields']); $fields = am($this->settings[$model->currentModel], $this->runtime[$model->currentModel]['fields']);
$addFields = array(); $addFields = array();
if (is_array($query['fields'])) { if (is_array($query['fields'])) {
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {
$field = ife(is_numeric($key), $value, $key); $field = ife(is_numeric($key), $value, $key);
if (in_array($model->name.'.*', $query['fields']) || $autoFields || in_array($model->name.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) { if (in_array($model->currentModel.'.*', $query['fields']) || $autoFields || in_array($model->currentModel.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) {
$addFields[] = $field; $addFields[] = $field;
} }
} }
@ -127,7 +127,7 @@ class TranslateBehavior extends ModelBehavior {
if ($addFields) { if ($addFields) {
foreach ($addFields as $field) { foreach ($addFields as $field) {
foreach (array($field, $model->name.'.'.$field) as $_field) { foreach (array($field, $model->currentModel.'.'.$field) as $_field) {
$key = array_search($_field, $query['fields']); $key = array_search($_field, $query['fields']);
if ($key !== false) { if ($key !== false) {
@ -143,8 +143,8 @@ class TranslateBehavior extends ModelBehavior {
'alias' => 'I18n__'.$field.'__'.$_locale, 'alias' => 'I18n__'.$field.'__'.$_locale,
'table' => $db->name($tablePrefix . 'i18n'), 'table' => $db->name($tablePrefix . 'i18n'),
'conditions' => array( 'conditions' => array(
$model->name.'.id' => '{$__cakeIdentifier[I18n__'.$field.'__'.$_locale.'.foreign_key]__$}', $model->currentModel.'.id' => '{$__cakeIdentifier[I18n__'.$field.'__'.$_locale.'.foreign_key]__$}',
'I18n__'.$field.'__'.$_locale.'.model' => $model->name, 'I18n__'.$field.'__'.$_locale.'.model' => $model->currentModel,
'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $field, 'I18n__'.$field.'__'.$_locale.'.'.$RuntimeModel->displayField => $field,
'I18n__'.$field.'__'.$_locale.'.locale' => $_locale)); 'I18n__'.$field.'__'.$_locale.'.locale' => $_locale));
} }
@ -155,47 +155,47 @@ class TranslateBehavior extends ModelBehavior {
'alias' => 'I18n__'.$field, 'alias' => 'I18n__'.$field,
'table' => $db->name($tablePrefix . 'i18n'), 'table' => $db->name($tablePrefix . 'i18n'),
'conditions' => array( 'conditions' => array(
$model->name.'.id' => '{$__cakeIdentifier[I18n__'.$field.'.foreign_key]__$}', $model->currentModel.'.id' => '{$__cakeIdentifier[I18n__'.$field.'.foreign_key]__$}',
'I18n__'.$field.'.model' => $model->name, 'I18n__'.$field.'.model' => $model->currentModel,
'I18n__'.$field.'.'.$RuntimeModel->displayField => $field)); 'I18n__'.$field.'.'.$RuntimeModel->displayField => $field));
$query['conditions'][$db->name('I18n__'.$field.'.locale')] = $locale; $query['conditions'][$db->name('I18n__'.$field.'.locale')] = $locale;
} }
} }
} }
$query['fields'] = am($query['fields']); $query['fields'] = am($query['fields']);
$this->runtime[$model->name]['beforeFind'] = $addFields; $this->runtime[$model->currentModel]['beforeFind'] = $addFields;
return $query; return $query;
} }
/** /**
* Callback * Callback
*/ */
function afterFind(&$model, $results, $primary) { function afterFind(&$model, $results, $primary) {
$this->runtime[$model->name]['fields'] = array(); $this->runtime[$model->currentModel]['fields'] = array();
$locale = $this->_getLocale($model); $locale = $this->_getLocale($model);
if (empty($locale) || empty($results) || empty($this->runtime[$model->name]['beforeFind'])) { if (empty($locale) || empty($results) || empty($this->runtime[$model->currentModel]['beforeFind'])) {
return $results; return $results;
} }
$beforeFind = $this->runtime[$model->name]['beforeFind']; $beforeFind = $this->runtime[$model->currentModel]['beforeFind'];
foreach ($results as $key => $row) { foreach ($results as $key => $row) {
$results[$key][$model->name]['locale'] = ife(is_array($locale), @$locale[0], $locale); $results[$key][$model->currentModel]['locale'] = ife(is_array($locale), @$locale[0], $locale);
foreach ($beforeFind as $field) { foreach ($beforeFind as $field) {
if (is_array($locale)) { if (is_array($locale)) {
foreach ($locale as $_locale) { foreach ($locale as $_locale) {
if (!isset($results[$key][$model->name][$field]) && !empty($results[$key]['I18n__'.$field.'__'.$_locale]['content'])) { if (!isset($results[$key][$model->currentModel][$field]) && !empty($results[$key]['I18n__'.$field.'__'.$_locale]['content'])) {
$results[$key][$model->name][$field] = $results[$key]['I18n__'.$field.'__'.$_locale]['content']; $results[$key][$model->currentModel][$field] = $results[$key]['I18n__'.$field.'__'.$_locale]['content'];
} }
unset($results[$key]['I18n__'.$field.'__'.$_locale]); unset($results[$key]['I18n__'.$field.'__'.$_locale]);
} }
if (!isset($results[$key][$model->name][$field])) { if (!isset($results[$key][$model->currentModel][$field])) {
$results[$key][$model->name][$field] = ''; $results[$key][$model->currentModel][$field] = '';
} }
} else { } else {
$value = ife(empty($results[$key]['I18n__'.$field]['content']), '', $results[$key]['I18n__'.$field]['content']); $value = ife(empty($results[$key]['I18n__'.$field]['content']), '', $results[$key]['I18n__'.$field]['content']);
$results[$key][$model->name][$field] = $value; $results[$key][$model->currentModel][$field] = $value;
unset($results[$key]['I18n__'.$field]); unset($results[$key]['I18n__'.$field]);
} }
} }
@ -211,31 +211,31 @@ class TranslateBehavior extends ModelBehavior {
if (empty($locale) || is_array($locale)) { if (empty($locale) || is_array($locale)) {
return true; return true;
} }
$fields = am($this->settings[$model->name], $this->runtime[$model->name]['fields']); $fields = am($this->settings[$model->currentModel], $this->runtime[$model->currentModel]['fields']);
$tempData = array(); $tempData = array();
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {
$field = ife(is_numeric($key), $value, $key); $field = ife(is_numeric($key), $value, $key);
if (isset($model->data[$model->name][$field])) { if (isset($model->data[$model->currentModel][$field])) {
$tempData[$field] = $model->data[$model->name][$field]; $tempData[$field] = $model->data[$model->currentModel][$field];
unset($model->data[$model->name][$field]); unset($model->data[$model->currentModel][$field]);
} }
} }
$this->runtime[$model->name]['beforeSave'] = $tempData; $this->runtime[$model->currentModel]['beforeSave'] = $tempData;
return true; return true;
} }
/** /**
* Callback * Callback
*/ */
function afterSave(&$model, $created) { function afterSave(&$model, $created) {
if (!isset($this->runtime[$model->name]['beforeSave'])) { if (!isset($this->runtime[$model->currentModel]['beforeSave'])) {
return true; return true;
} }
$locale = $this->_getLocale($model); $locale = $this->_getLocale($model);
$tempData = $this->runtime[$model->name]['beforeSave']; $tempData = $this->runtime[$model->currentModel]['beforeSave'];
unset($this->runtime[$model->name]['beforeSave']); unset($this->runtime[$model->currentModel]['beforeSave']);
$conditions = array('locale' => $locale, 'model' => $model->name, 'foreign_key' => $model->id); $conditions = array('locale' => $locale, 'model' => $model->currentModel, 'foreign_key' => $model->id);
$RuntimeModel =& $this->translateModel($model); $RuntimeModel =& $this->translateModel($model);
if (empty($created)) { if (empty($created)) {
@ -244,7 +244,7 @@ class TranslateBehavior extends ModelBehavior {
if ($translations) { if ($translations) {
foreach ($translations as $id => $field) { foreach ($translations as $id => $field) {
$RuntimeModel->create(); $RuntimeModel->create();
$RuntimeModel->save(array($RuntimeModel->name => array('id' => $id, 'content' => $tempData[$field]))); $RuntimeModel->save(array($RuntimeModel->currentModel => array('id' => $id, 'content' => $tempData[$field])));
unset($tempData[$field]); unset($tempData[$field]);
} }
} }
@ -262,7 +262,7 @@ class TranslateBehavior extends ModelBehavior {
*/ */
function afterDelete(&$model) { function afterDelete(&$model) {
$RuntimeModel =& $this->translateModel($model); $RuntimeModel =& $this->translateModel($model);
$conditions = array('model' => $model->name, 'foreign_key' => $model->id); $conditions = array('model' => $model->currentModel, 'foreign_key' => $model->id);
$RuntimeModel->deleteAll($conditions); $RuntimeModel->deleteAll($conditions);
} }
/** /**
@ -286,7 +286,7 @@ class TranslateBehavior extends ModelBehavior {
* @return object * @return object
*/ */
function &translateModel(&$model) { function &translateModel(&$model) {
if (!isset($this->runtime[$model->name]['model'])) { if (!isset($this->runtime[$model->currentModel]['model'])) {
if (!isset($model->translateModel) || empty($model->translateModel)) { if (!isset($model->translateModel) || empty($model->translateModel)) {
$className = 'I18nModel'; $className = 'I18nModel';
} else { } else {
@ -298,21 +298,21 @@ class TranslateBehavior extends ModelBehavior {
if (ClassRegistry::isKeySet($className)) { if (ClassRegistry::isKeySet($className)) {
if (PHP5) { if (PHP5) {
$this->runtime[$model->name]['model'] = ClassRegistry::getObject($className); $this->runtime[$model->currentModel]['model'] = ClassRegistry::getObject($className);
} else { } else {
$this->runtime[$model->name]['model'] =& ClassRegistry::getObject($className); $this->runtime[$model->currentModel]['model'] =& ClassRegistry::getObject($className);
} }
} else { } else {
if (PHP5) { if (PHP5) {
$this->runtime[$model->name]['model'] = new $className(); $this->runtime[$model->currentModel]['model'] = new $className();
} else { } else {
$this->runtime[$model->name]['model'] =& new $className(); $this->runtime[$model->currentModel]['model'] =& new $className();
} }
ClassRegistry::addObject($className, $this->runtime[$model->name]['model']); ClassRegistry::addObject($className, $this->runtime[$model->currentModel]['model']);
ClassRegistry::map($className, $className); ClassRegistry::map($className, $className);
} }
} }
return $this->runtime[$model->name]['model']; return $this->runtime[$model->currentModel]['model'];
} }
/** /**
* Bind translation for fields, optionally with hasMany association for * Bind translation for fields, optionally with hasMany association for
@ -333,7 +333,7 @@ class TranslateBehavior extends ModelBehavior {
} }
$associations = array(); $associations = array();
$RuntimeModel =& $this->translateModel($model); $RuntimeModel =& $this->translateModel($model);
$default = array('className' => $RuntimeModel->name, 'foreignKey' => 'foreign_key'); $default = array('className' => $RuntimeModel->currentModel, 'foreignKey' => 'foreign_key');
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {
if (is_numeric($key)) { if (is_numeric($key)) {
@ -344,42 +344,42 @@ class TranslateBehavior extends ModelBehavior {
$association = $value; $association = $value;
} }
if (array_key_exists($field, $this->settings[$model->name])) { if (array_key_exists($field, $this->settings[$model->currentModel])) {
unset($this->settings[$model->name][$field]); unset($this->settings[$model->currentModel][$field]);
} elseif (in_array($field, $this->settings[$model->name])) { } elseif (in_array($field, $this->settings[$model->currentModel])) {
$this->settings[$model->name] = am(array_diff_assoc($this->settings[$model->name], array($field))); $this->settings[$model->currentModel] = am(array_diff_assoc($this->settings[$model->currentModel], array($field)));
} }
if (array_key_exists($field, $this->runtime[$model->name]['fields'])) { if (array_key_exists($field, $this->runtime[$model->currentModel]['fields'])) {
unset($this->runtime[$model->name]['fields'][$field]); unset($this->runtime[$model->currentModel]['fields'][$field]);
} elseif (in_array($field, $this->runtime[$model->name]['fields'])) { } elseif (in_array($field, $this->runtime[$model->currentModel]['fields'])) {
$this->runtime[$model->name]['fields'] = am(array_diff_assoc($this->runtime[$model->name]['fields'], array($field))); $this->runtime[$model->currentModel]['fields'] = am(array_diff_assoc($this->runtime[$model->currentModel]['fields'], array($field)));
} }
if (is_null($association)) { if (is_null($association)) {
if ($reset) { if ($reset) {
$this->runtime[$model->name]['fields'][] = $field; $this->runtime[$model->currentModel]['fields'][] = $field;
} else { } else {
$this->settings[$model->name][] = $field; $this->settings[$model->currentModel][] = $field;
} }
} else { } else {
if ($reset) { if ($reset) {
$this->runtime[$model->name]['fields'][$field] = $association; $this->runtime[$model->currentModel]['fields'][$field] = $association;
} else { } else {
$this->settings[$model->name][$field] = $association; $this->settings[$model->currentModel][$field] = $association;
} }
foreach (array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany') as $type) { foreach (array('hasOne', 'hasMany', 'belongsTo', 'hasAndBelongsToMany') as $type) {
if (isset($model->{$type}[$association]) || isset($model->__backAssociation[$type][$association])) { if (isset($model->{$type}[$association]) || isset($model->__backAssociation[$type][$association])) {
trigger_error('Association '.$association.' is already binded to model '.$model->name, E_USER_ERROR); trigger_error('Association '.$association.' is already binded to model '.$model->currentModel, E_USER_ERROR);
return false; return false;
} }
} }
$associations[$association] = am($default, array('conditions' => array( $associations[$association] = am($default, array('conditions' => array(
'model' => $model->name, 'model' => $model->currentModel,
$RuntimeModel->displayField => $field))); $RuntimeModel->displayField => $field)));
} }
} }
@ -406,7 +406,7 @@ class TranslateBehavior extends ModelBehavior {
$fields = array($fields); $fields = array($fields);
} }
$RuntimeModel =& $this->translateModel($model); $RuntimeModel =& $this->translateModel($model);
$default = array('className' => $RuntimeModel->name, 'foreignKey' => 'foreign_key'); $default = array('className' => $RuntimeModel->currentModel, 'foreignKey' => 'foreign_key');
$associations = array(); $associations = array();
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {
@ -418,18 +418,18 @@ class TranslateBehavior extends ModelBehavior {
$association = $value; $association = $value;
} }
if (array_key_exists($field, $this->settings[$model->name])) { if (array_key_exists($field, $this->settings[$model->currentModel])) {
unset($this->settings[$model->name][$field]); unset($this->settings[$model->currentModel][$field]);
} elseif (in_array($field, $this->settings[$model->name])) { } elseif (in_array($field, $this->settings[$model->currentModel])) {
$this->settings[$model->name] = am(array_diff_assoc($this->settings[$model->name], array($field))); $this->settings[$model->currentModel] = am(array_diff_assoc($this->settings[$model->currentModel], array($field)));
} }
if (array_key_exists($field, $this->runtime[$model->name]['fields'])) { if (array_key_exists($field, $this->runtime[$model->currentModel]['fields'])) {
unset($this->runtime[$model->name]['fields'][$field]); unset($this->runtime[$model->currentModel]['fields'][$field]);
} elseif (in_array($field, $this->runtime[$model->name]['fields'])) { } elseif (in_array($field, $this->runtime[$model->currentModel]['fields'])) {
$this->runtime[$model->name]['fields'] = am(array_diff_assoc($this->runtime[$model->name]['fields'], array($field))); $this->runtime[$model->currentModel]['fields'] = am(array_diff_assoc($this->runtime[$model->currentModel]['fields'], array($field)));
} }
if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) { if (!is_null($association) && (isset($model->hasMany[$association]) || isset($model->__backAssociation['hasMany'][$association]))) {

View file

@ -52,7 +52,7 @@ class TreeBehavior extends ModelBehavior {
$parent =& $model->{$data['className']}; $parent =& $model->{$data['className']};
$settings['scope'] = $model->escapeField($data['foreignKey']) . ' = ' . $parent->escapeField($parent->primaryKey, $settings['scope']); $settings['scope'] = $model->escapeField($data['foreignKey']) . ' = ' . $parent->escapeField($parent->primaryKey, $settings['scope']);
}*/ }*/
$this->settings[$model->name] = $settings; $this->settings[$model->currentModel] = $settings;
} }
/** /**
* After save method. Called after all saves * After save method. Called after all saves
@ -65,17 +65,17 @@ class TreeBehavior extends ModelBehavior {
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
function afterSave(&$model, $created) { function afterSave(&$model, $created) {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if (!$enabled) { if (!$enabled) {
return true; return true;
} }
if ($created) { if ($created) {
if ((isset($model->data[$model->name][$parent])) && $model->data[$model->name][$parent]) { if ((isset($model->data[$model->currentModel][$parent])) && $model->data[$model->currentModel][$parent]) {
return $this->_setParent($model, $model->data[$model->name][$parent]); return $this->_setParent($model, $model->data[$model->currentModel][$parent]);
} }
} elseif ($__parentChange) { } elseif ($__parentChange) {
$this->settings[$model->name]['__parentChange'] = false; $this->settings[$model->currentModel]['__parentChange'] = false;
return $this->_setParent($model, $model->data[$model->name][$parent]); return $this->_setParent($model, $model->data[$model->currentModel][$parent]);
} }
} }
/** /**
@ -87,13 +87,13 @@ class TreeBehavior extends ModelBehavior {
* @return boolean true to continue, false to abort the delete * @return boolean true to continue, false to abort the delete
*/ */
function beforeDelete(&$model) { function beforeDelete(&$model) {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if (!$enabled) { if (!$enabled) {
return true; return true;
} }
list($name, $data)= array( list($name, $data)= array(
$model->name, $model->currentModel,
$model->read()); $model->read());
$data= $data[$name]; $data= $data[$name];
@ -121,44 +121,44 @@ class TreeBehavior extends ModelBehavior {
* @return boolean true to continue, false to abort the save * @return boolean true to continue, false to abort the save
*/ */
function beforeSave(&$model) { function beforeSave(&$model) {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if (!$enabled) { if (!$enabled) {
return true; return true;
} }
if (isset($model->data[$model->name][$model->primaryKey])) { if (isset($model->data[$model->currentModel][$model->primaryKey])) {
if ($model->data[$model->name][$model->primaryKey]) { if ($model->data[$model->currentModel][$model->primaryKey]) {
if (!$model->id) { if (!$model->id) {
$model->id = $model->data[$model->name][$model->primaryKey]; $model->id = $model->data[$model->currentModel][$model->primaryKey];
} }
} }
unset ($model->data[$model->name][$model->primaryKey]); unset ($model->data[$model->currentModel][$model->primaryKey]);
} }
if (!$model->id) { if (!$model->id) {
if ((!isset($model->data[$model->name][$parent])) || (!$model->data[$model->name][$parent])) { if ((!isset($model->data[$model->currentModel][$parent])) || (!$model->data[$model->currentModel][$parent])) {
$edge = $this->__getMax($model, $scope, $right); $edge = $this->__getMax($model, $scope, $right);
$model->data[$model->name][$left]= $edge +1; $model->data[$model->currentModel][$left]= $edge +1;
$model->data[$model->name][$right]= $edge +2; $model->data[$model->currentModel][$right]= $edge +2;
} else { } else {
$parentNode = $model->find(array($scope, $model->escapeField() => $model->data[$model->name][$parent]), $parentNode = $model->find(array($scope, $model->escapeField() => $model->data[$model->currentModel][$parent]),
array($model->primaryKey), null, -1); array($model->primaryKey), null, -1);
if (!$parentNode) { if (!$parentNode) {
return false; return false;
} }
} }
} elseif (isset($model->data[$model->name][$parent])) { } elseif (isset($model->data[$model->currentModel][$parent])) {
if ($model->data[$model->name][$parent] != $model->field($parent)) { if ($model->data[$model->currentModel][$parent] != $model->field($parent)) {
$this->settings[$model->name]['__parentChange'] = true; $this->settings[$model->currentModel]['__parentChange'] = true;
} }
if (!$model->data[$model->name][$parent]) { if (!$model->data[$model->currentModel][$parent]) {
$model->data[$model->name][$parent]= null; $model->data[$model->currentModel][$parent]= null;
} else { } else {
list($node) = array_values($model->find(array($scope,$model->escapeField() => $model->id), list($node) = array_values($model->find(array($scope,$model->escapeField() => $model->id),
array($model->primaryKey, $parent, $left, $right ), null, -1)); array($model->primaryKey, $parent, $left, $right ), null, -1));
$parentNode = $model->find(array($scope, $model->escapeField() => $model->data[$model->name][$parent]), $parentNode = $model->find(array($scope, $model->escapeField() => $model->data[$model->currentModel][$parent]),
array($model->primaryKey, $left, $right), null, -1); array($model->primaryKey, $left, $right), null, -1);
if (!$parentNode) { if (!$parentNode) {
return false; return false;
@ -192,7 +192,7 @@ class TreeBehavior extends ModelBehavior {
} elseif (!$id) { } elseif (!$id) {
$id = null; $id = null;
} }
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if ($direct) { if ($direct) {
return $model->findCount(array($scope, $model->escapeField($parent) => $id)); return $model->findCount(array($scope, $model->escapeField($parent) => $id));
@ -201,7 +201,7 @@ class TreeBehavior extends ModelBehavior {
return $model->findCount($scope); return $model->findCount($scope);
} }
elseif (!empty ($model->data)) { elseif (!empty ($model->data)) {
$data = $model->data[$model->name]; $data = $model->data[$model->currentModel];
} else { } else {
list($data)= array_values($model->find(array($scope, $model->escapeField() => $id), null, null, -1)); list($data)= array_values($model->find(array($scope, $model->escapeField() => $id), null, null, -1));
} }
@ -231,11 +231,11 @@ class TreeBehavior extends ModelBehavior {
} elseif (!$id) { } elseif (!$id) {
$id = null; $id = null;
} }
$name = $model->name; $name = $model->currentModel;
extract($this->settings[$name]); extract($this->settings[$name]);
if (!$order) { if (!$order) {
$order = $model->name . '.' . $left . ' asc'; $order = $model->currentModel . '.' . $left . ' asc';
} }
if ($direct) { if ($direct) {
return $model->findAll(array($scope, $model->escapeField($parent) => $id), $fields, $order, $limit, $page, $recursive); return $model->findAll(array($scope, $model->escapeField($parent) => $id), $fields, $order, $limit, $page, $recursive);
@ -262,7 +262,7 @@ class TreeBehavior extends ModelBehavior {
* @access public * @access public
*/ */
function generatetreelist(&$model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = -1) { function generatetreelist(&$model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = -1) {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if ($keyPath == null && $valuePath == null && $model->hasField($model->displayField)) { if ($keyPath == null && $valuePath == null && $model->hasField($model->displayField)) {
$fields = array($model->primaryKey, $model->displayField, $left, $right); $fields = array($model->primaryKey, $model->displayField, $left, $right);
@ -271,11 +271,11 @@ class TreeBehavior extends ModelBehavior {
} }
if ($keyPath == null) { if ($keyPath == null) {
$keyPath = '{n}.' . $model->name . '.' . $model->primaryKey; $keyPath = '{n}.' . $model->currentModel . '.' . $model->primaryKey;
} }
if ($valuePath == null) { if ($valuePath == null) {
$valuePath = array('{0}{1}', '{n}.tree_prefix', '{n}.' . $model->name . '.' . $model->displayField); $valuePath = array('{0}{1}', '{n}.tree_prefix', '{n}.' . $model->currentModel . '.' . $model->displayField);
} elseif (is_string($valuePath)) { } elseif (is_string($valuePath)) {
$valuePath = array('{0}{1}', '{n}.tree_prefix', $valuePath); $valuePath = array('{0}{1}', '{n}.tree_prefix', $valuePath);
@ -288,11 +288,11 @@ class TreeBehavior extends ModelBehavior {
$stack = array(); $stack = array();
foreach ($results as $i => $result) { foreach ($results as $i => $result) {
while ($stack && ($stack[count($stack)-1] < $result[$model->name][$right])) { while ($stack && ($stack[count($stack)-1] < $result[$model->currentModel][$right])) {
array_pop($stack); array_pop($stack);
} }
$results[$i]['tree_prefix'] = str_repeat($spacer,count($stack)); $results[$i]['tree_prefix'] = str_repeat($spacer,count($stack));
$stack[] = $result[$model->name][$right]; $stack[] = $result[$model->currentModel][$right];
} }
return Set::combine($results, $keyPath, $valuePath); return Set::combine($results, $keyPath, $valuePath);
} }
@ -311,11 +311,11 @@ class TreeBehavior extends ModelBehavior {
if (empty ($id)) { if (empty ($id)) {
$id = $model->id; $id = $model->id;
} }
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
$parentId = $model->read($parent, $id); $parentId = $model->read($parent, $id);
if ($parentId) { if ($parentId) {
$parentId = $parentId[$model->name][$parent]; $parentId = $parentId[$model->currentModel][$parent];
$parent = $model->find(array($model->escapeField() => $parentId), $fields, null, $recursive); $parent = $model->find(array($model->escapeField() => $parentId), $fields, null, $recursive);
return $parent; return $parent;
@ -337,7 +337,7 @@ class TreeBehavior extends ModelBehavior {
if (empty ($id)) { if (empty ($id)) {
$id = $model->id; $id = $model->id;
} }
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
@list($item) = array_values($model->find(array($model->escapeField() => $id), array($left, $right), null, -1)); @list($item) = array_values($model->find(array($model->escapeField() => $id), array($left, $right), null, -1));
if (empty ($item)) { if (empty ($item)) {
@ -366,7 +366,7 @@ class TreeBehavior extends ModelBehavior {
if (empty ($id)) { if (empty ($id)) {
$id = $model->id; $id = $model->id;
} }
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
list($node) = array_values($model->find(array($scope, $model->escapeField() => $id), list($node) = array_values($model->find(array($scope, $model->escapeField() => $id),
array($model->primaryKey, $left, $right, $parent), null, -1)); array($model->primaryKey, $left, $right, $parent), null, -1));
if ($node[$parent]) { if ($node[$parent]) {
@ -410,7 +410,7 @@ class TreeBehavior extends ModelBehavior {
if (empty ($id)) { if (empty ($id)) {
$id = $model->id; $id = $model->id;
} }
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
list($node) = array_values($model->find(array($scope, $model->escapeField() => $id), list($node) = array_values($model->find(array($scope, $model->escapeField() => $id),
array($model->primaryKey, $left, $right, $parent ), null, -1)); array($model->primaryKey, $left, $right, $parent ), null, -1));
if ($node[$parent]) { if ($node[$parent]) {
@ -453,30 +453,30 @@ class TreeBehavior extends ModelBehavior {
* @access public * @access public
*/ */
function recover(&$model, $mode = 'parent') { function recover(&$model, $mode = 'parent') {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
$model->recursive = -1; $model->recursive = -1;
if ($mode == 'parent') { if ($mode == 'parent') {
$count = 1; $count = 1;
foreach ($model->findAll($scope, array($model->primaryKey), $left) as $array) { foreach ($model->findAll($scope, array($model->primaryKey), $left) as $array) {
$model->{$model->primaryKey} = $array[$model->name][$model->primaryKey]; $model->{$model->primaryKey} = $array[$model->currentModel][$model->primaryKey];
$lft = $count++; $lft = $count++;
$rght = $count++; $rght = $count++;
$model->save(array($left => $lft,$right => $rght)); $model->save(array($left => $lft,$right => $rght));
} }
foreach ($model->findAll($scope, array($model->primaryKey,$parent), $left) as $array) { foreach ($model->findAll($scope, array($model->primaryKey,$parent), $left) as $array) {
$model->create(); $model->create();
$model->id = $array[$model->name][$model->primaryKey]; $model->id = $array[$model->currentModel][$model->primaryKey];
$this->_setParent($model, $array[$model->name][$parent], true); $this->_setParent($model, $array[$model->currentModel][$parent], true);
} }
} else { } else {
foreach ($model->findAll($scope, array($model->primaryKey, $parent), $left) as $array) { foreach ($model->findAll($scope, array($model->primaryKey, $parent), $left) as $array) {
$path = $this->getpath($model, $array[$model->name][$model->primaryKey]); $path = $this->getpath($model, $array[$model->currentModel][$model->primaryKey]);
if ($path == null || count($path) < 2) { if ($path == null || count($path) < 2) {
$parentId = null; $parentId = null;
} else { } else {
$parentId = $path[count($path) - 2][$model->name][$model->primaryKey]; $parentId = $path[count($path) - 2][$model->currentModel][$model->primaryKey];
} }
$model->updateAll(array($parent => $parentId), array($model->primaryKey => $array[$model->name][$model->primaryKey])); $model->updateAll(array($parent => $parentId), array($model->primaryKey => $array[$model->currentModel][$model->primaryKey]));
} }
} }
} }
@ -496,7 +496,7 @@ class TreeBehavior extends ModelBehavior {
if (empty ($id)) { if (empty ($id)) {
$id = $model->id; $id = $model->id;
} }
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
list($node) = array_values($model->find( list($node) = array_values($model->find(
array($scope, $model->escapeField() => $id), array($scope, $model->escapeField() => $id),
array($model->primaryKey, $left, $right, $parent), null, -1) array($model->primaryKey, $left, $right, $parent), null, -1)
@ -543,7 +543,7 @@ class TreeBehavior extends ModelBehavior {
* @access public * @access public
*/ */
function setparent(&$model, $parentId = null , $created = null) { function setparent(&$model, $parentId = null , $created = null) {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if ($created === false && $parentId == $model->field($parent)) { if ($created === false && $parentId == $model->field($parent)) {
return true; return true;
} }
@ -560,7 +560,7 @@ class TreeBehavior extends ModelBehavior {
* @access public * @access public
*/ */
function verify(&$model) { function verify(&$model) {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if (!$model->findCount($scope)) { if (!$model->findCount($scope)) {
return true; return true;
} }
@ -586,24 +586,24 @@ class TreeBehavior extends ModelBehavior {
$model->bindModel(array('belongsTo' => array('VerifyParent' => array( $model->bindModel(array('belongsTo' => array('VerifyParent' => array(
'className' => $model->name, 'className' => $model->currentModel,
'foreignKey' => $parent, 'foreignKey' => $parent,
'fields' => array($model->primaryKey, $left, $right, $parent) 'fields' => array($model->primaryKey, $left, $right, $parent)
)))); ))));
foreach ($model->findAll($scope, null, null, null, null, 1) as $instance) { foreach ($model->findAll($scope, null, null, null, null, 1) as $instance) {
if ($instance[$model->name][$parent]) { if ($instance[$model->currentModel][$parent]) {
if (!$instance['VerifyParent'][$model->primaryKey]) { if (!$instance['VerifyParent'][$model->primaryKey]) {
$errors[] = array('node', $instance[$model->name][$model->primaryKey], $errors[] = array('node', $instance[$model->currentModel][$model->primaryKey],
'The parent node ' . $instance[$model->name][$parent] . ' doesn\'t exist'); 'The parent node ' . $instance[$model->currentModel][$parent] . ' doesn\'t exist');
} elseif ($instance[$model->name][$left] < $instance['VerifyParent'][$left]) { } elseif ($instance[$model->currentModel][$left] < $instance['VerifyParent'][$left]) {
$errors[] = array('node', $instance[$model->name][$model->primaryKey], $errors[] = array('node', $instance[$model->currentModel][$model->primaryKey],
'left less than parent (node ' . $instance['VerifyParent'][$model->primaryKey] . ').'); 'left less than parent (node ' . $instance['VerifyParent'][$model->primaryKey] . ').');
} elseif ($instance[$model->name][$right] > $instance['VerifyParent'][$right]) { } elseif ($instance[$model->currentModel][$right] > $instance['VerifyParent'][$right]) {
$errors[] = array('node', $instance[$model->name][$model->primaryKey], $errors[] = array('node', $instance[$model->currentModel][$model->primaryKey],
'right greater than parent (node ' . $instance['VerifyParent'][$model->primaryKey] . ').'); 'right greater than parent (node ' . $instance['VerifyParent'][$model->primaryKey] . ').');
} }
} elseif ($model->findCount(array($scope, $left . '< ' . $instance[$model->name][$left], $right . '> ' . $instance[$model->name][$right]))) { } elseif ($model->findCount(array($scope, $left . '< ' . $instance[$model->currentModel][$left], $right . '> ' . $instance[$model->currentModel][$right]))) {
$errors[] = array('node', $instance[$model->name][$model->primaryKey], 'The parent field is blank, but has a parent'); $errors[] = array('node', $instance[$model->currentModel][$model->primaryKey], 'The parent field is blank, but has a parent');
} }
} }
@ -626,7 +626,7 @@ class TreeBehavior extends ModelBehavior {
* @access protected * @access protected
*/ */
function _setParent(&$model, $parentId = null) { function _setParent(&$model, $parentId = null) {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
list($node) = array_values($model->find(array($scope, $model->escapeField() => $model->id), list($node) = array_values($model->find(array($scope, $model->escapeField() => $model->id),
array($model->primaryKey, $parent, $left, $right), null, -1)); array($model->primaryKey, $parent, $left, $right), null, -1));
$edge = $this->__getMax($model, $scope, $right); $edge = $this->__getMax($model, $scope, $right);
@ -710,7 +710,7 @@ class TreeBehavior extends ModelBehavior {
* @access private * @access private
*/ */
function __sync(&$model, $shift, $dir = '+', $conditions = array(), $field = 'both') { function __sync(&$model, $shift, $dir = '+', $conditions = array(), $field = 'both') {
extract($this->settings[$model->name]); extract($this->settings[$model->currentModel]);
if ($field == 'both') { if ($field == 'both') {
$this->__sync($model, $shift, $dir, $conditions, $left); $this->__sync($model, $shift, $dir, $conditions, $left);
$field = $right; $field = $right;

View file

@ -408,9 +408,9 @@ class DataSource extends Object {
if (strpos($query, $key) !== false) { if (strpos($query, $key) !== false) {
switch($key) { switch($key) {
case '{$__cakeID__$}': case '{$__cakeID__$}':
if (isset($data[$model->name]) || isset($data[$association])) { if (isset($data[$model->currentModel]) || isset($data[$association])) {
if (isset($data[$model->name][$model->primaryKey])) { if (isset($data[$model->currentModel][$model->primaryKey])) {
$val = $data[$model->name][$model->primaryKey]; $val = $data[$model->currentModel][$model->primaryKey];
} elseif (isset($data[$association][$model->primaryKey])) { } elseif (isset($data[$association][$model->primaryKey])) {
$val = $data[$association][$model->primaryKey]; $val = $data[$association][$model->primaryKey];
} }
@ -435,8 +435,8 @@ class DataSource extends Object {
if (isset($assoc['foreignKey'])) { if (isset($assoc['foreignKey'])) {
$foreignKey = $assoc['foreignKey']; $foreignKey = $assoc['foreignKey'];
if (isset($data[$model->name][$foreignKey])) { if (isset($data[$model->currentModel][$foreignKey])) {
$val = $data[$model->name][$foreignKey]; $val = $data[$model->currentModel][$foreignKey];
} elseif (isset($data[$association][$foreignKey])) { } elseif (isset($data[$association][$foreignKey])) {
$val = $data[$association][$foreignKey]; $val = $data[$association][$foreignKey];
} else { } else {
@ -475,7 +475,7 @@ class DataSource extends Object {
* @return unknown * @return unknown
*/ */
function resolveKey($model, $key) { function resolveKey($model, $key) {
return $model->name . $key; return $model->currentModel . $key;
} }
/** /**
* Closes the current datasource. * Closes the current datasource.

View file

@ -334,7 +334,7 @@ class DboAdodb extends DboSource {
*/ */
function fields(&$model, $alias = null, $fields = null, $quote = true) { function fields(&$model, $alias = null, $fields = null, $quote = true) {
if (empty($alias)) { if (empty($alias)) {
$alias = $model->name; $alias = $model->currentModel;
} }
if (!is_array($fields)) { if (!is_array($fields)) {

View file

@ -189,7 +189,7 @@ class DboFirebird extends DboSource {
* @return array Fields in table. Keys are name and type * @return array Fields in table. Keys are name and type
*/ */
function describe(&$model) { function describe(&$model) {
$this->modeltmp[$model->table] = $model->name; $this->modeltmp[$model->table] = $model->currentModel;
$cache = parent::describe($model); $cache = parent::describe($model);
if ($cache != null) { if ($cache != null) {

View file

@ -265,7 +265,7 @@ class DboMssql extends DboSource {
*/ */
function fields(&$model, $alias = null, $fields = array(), $quote = true) { function fields(&$model, $alias = null, $fields = array(), $quote = true) {
if (empty($alias)) { if (empty($alias)) {
$alias = $model->name; $alias = $model->currentModel;
} }
$fields = parent::fields($model, $alias, $fields, false); $fields = parent::fields($model, $alias, $fields, false);
$count = count($fields); $count = count($fields);

View file

@ -374,7 +374,7 @@ class DboPostgres extends DboSource {
*/ */
function fields(&$model, $alias = null, $fields = array(), $quote = true) { function fields(&$model, $alias = null, $fields = array(), $quote = true) {
if (empty($alias)) { if (empty($alias)) {
$alias = $model->name; $alias = $model->currentModel;
} }
$fields = parent::fields($model, $alias, $fields, false); $fields = parent::fields($model, $alias, $fields, false);

View file

@ -220,9 +220,9 @@ class DboSource extends DataSource {
$query = array(); $query = array();
foreach ($field as $f) { foreach ($field as $f) {
if (!is_array($params[$c]) && !empty($params[$c]) && $params[$c] !== true && $params[$c] !== false) { if (!is_array($params[$c]) && !empty($params[$c]) && $params[$c] !== true && $params[$c] !== false) {
$query[$args[2]->name . '.' . $f] = '= ' . $params[$c]; $query[$args[2]->currentModel . '.' . $f] = '= ' . $params[$c];
} else { } else {
$query[$args[2]->name . '.' . $f] = $params[$c]; $query[$args[2]->currentModel . '.' . $f] = $params[$c];
} }
$c++; $c++;
} }
@ -552,7 +552,7 @@ class DboSource extends DataSource {
$linkModel =& $model->{$assoc}; $linkModel =& $model->{$assoc};
$external = isset($assocData['external']); $external = isset($assocData['external']);
if ($model->name == $linkModel->name && $type != 'hasAndBelongsToMany' && $type != 'hasMany') { if ($model->currentModel == $linkModel->currentModel && $type != 'hasAndBelongsToMany' && $type != 'hasMany') {
if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) { if (true === $this->generateSelfAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) {
$linkedModels[] = $type . '/' . $assoc; $linkedModels[] = $type . '/' . $assoc;
} }
@ -568,7 +568,7 @@ class DboSource extends DataSource {
} }
// Build final query SQL // Build final query SQL
$query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null); $query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null);
$resultSet = $this->fetchAll($query, $model->cacheQueries, $model->name); $resultSet = $this->fetchAll($query, $model->cacheQueries, $model->currentModel);
if ($resultSet === false) { if ($resultSet === false) {
$model->onError(); $model->onError();
@ -633,7 +633,7 @@ class DboSource extends DataSource {
for ($j = 0; $j < $count2; $j++) { for ($j = 0; $j < $count2; $j++) {
$className = $key = $keys[$j]; $className = $key = $keys[$j];
if ($model->name != $className && !in_array($key, $filtered)) { if ($model->currentModel != $className && !in_array($key, $filtered)) {
if (!in_array($key, $filtering)) { if (!in_array($key, $filtering)) {
$filtering[] = $key; $filtering[] = $key;
} }
@ -669,7 +669,7 @@ class DboSource extends DataSource {
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) { if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
if (!isset($resultSet) || !is_array($resultSet)) { if (!isset($resultSet) || !is_array($resultSet)) {
if (Configure::read() > 0) { if (Configure::read() > 0) {
e('<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->name) . ' '); e('<div style = "font: Verdana bold 12px; color: #FF0000">' . sprintf(__('SQL Error in model %s:', true), $model->currentModel) . ' ');
if (isset($this->error) && $this->error != null) { if (isset($this->error) && $this->error != null) {
e($this->error); e($this->error);
} }
@ -689,7 +689,7 @@ class DboSource extends DataSource {
if (!empty($ins)) { if (!empty($ins)) {
$query = r('{$__cakeID__$}', join(', ', $ins), $query); $query = r('{$__cakeID__$}', join(', ', $ins), $query);
$fetch = $this->fetchAll($query, $model->cacheQueries, $model->name); $fetch = $this->fetchAll($query, $model->cacheQueries, $model->currentModel);
} }
if (!empty($fetch) && is_array($fetch)) { if (!empty($fetch) && is_array($fetch)) {
@ -699,7 +699,7 @@ class DboSource extends DataSource {
foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assoc1}; $deepModel =& $linkModel->{$assoc1};
if ($deepModel->alias != $model->name) { if ($deepModel->alias != $model->currentModel) {
$tmpStack = $stack; $tmpStack = $stack;
$tmpStack[] = $assoc1; $tmpStack[] = $assoc1;
if ($linkModel->useDbConfig == $deepModel->useDbConfig) { if ($linkModel->useDbConfig == $deepModel->useDbConfig) {
@ -735,7 +735,7 @@ class DboSource extends DataSource {
$q = $this->insertQueryData($query, null, $association, $assocData, $model, $linkModel, $stack); $q = $this->insertQueryData($query, null, $association, $assocData, $model, $linkModel, $stack);
if ($q != false) { if ($q != false) {
$fetch = $this->fetchAll($q, $model->cacheQueries, $model->name); $fetch = $this->fetchAll($q, $model->cacheQueries, $model->currentModel);
} else { } else {
$fetch = null; $fetch = null;
} }
@ -747,7 +747,7 @@ class DboSource extends DataSource {
if ($type !== 'hasAndBelongsToMany') { if ($type !== 'hasAndBelongsToMany') {
$q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack); $q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack);
if ($q != false) { if ($q != false) {
$fetch = $this->fetchAll($q, $model->cacheQueries, $model->name); $fetch = $this->fetchAll($q, $model->cacheQueries, $model->currentModel);
} else { } else {
$fetch = null; $fetch = null;
} }
@ -760,7 +760,7 @@ class DboSource extends DataSource {
foreach ($linkModel->{$type1} as $assoc1 => $assocData1) { foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel =& $linkModel->{$assoc1}; $deepModel =& $linkModel->{$assoc1};
if (($type1 === 'belongsTo') || ($deepModel->name === $model->name && $type === 'belongsTo') || ($deepModel->name != $model->name)) { if (($type1 === 'belongsTo') || ($deepModel->currentModel === $model->currentModel && $type === 'belongsTo') || ($deepModel->currentModel != $model->currentModel)) {
$tmpStack = $stack; $tmpStack = $stack;
$tmpStack[] = $assoc1; $tmpStack[] = $assoc1;
if ($linkModel->useDbConfig == $deepModel->useDbConfig) { if ($linkModel->useDbConfig == $deepModel->useDbConfig) {
@ -776,7 +776,7 @@ class DboSource extends DataSource {
if ($type == 'hasAndBelongsToMany') { if ($type == 'hasAndBelongsToMany') {
$merge = array(); $merge = array();
foreach($fetch as $j => $data) { foreach($fetch as $j => $data) {
if(isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->name][$model->primaryKey]) { if(isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->currentModel][$model->primaryKey]) {
if ($habtmFieldsCount > 2) { if ($habtmFieldsCount > 2) {
$merge[] = $data; $merge[] = $data;
} else { } else {
@ -807,10 +807,16 @@ class DboSource extends DataSource {
$count = 0; $count = 0;
$merged[$association] = array(); $merged[$association] = array();
foreach ($merge as $j => $data) { foreach ($merge as $j => $data) {
if (isset($value[$model->name]) && $value[$model->name][$model->primaryKey] === $data[$association][$model->hasMany[$association]['foreignKey']]) { if (isset($value[$model->currentModel]) && $value[$model->currentModel][$model->primaryKey] === $data[$association][$model->hasMany[$association]['foreignKey']]) {
if (count($data) > 1) { if (count($data) > 1) {
$data = am($data[$association], $data); $data = am($data[$association], $data);
unset($data[$association]); unset($data[$association]);
foreach ($data as $key => $name) {
if (is_numeric($key)) {
$data[$association][] = $name;
unset($data[$key]);
}
}
$merged[$association][] = $data; $merged[$association][] = $data;
} else { } else {
$merged[$association][] = $data[$association]; $merged[$association][] = $data[$association];
@ -818,9 +824,9 @@ class DboSource extends DataSource {
} }
$count++; $count++;
} }
if (isset($value[$model->name])) { if (isset($value[$model->currentModel])) {
$resultSet[$i] = Set::pushDiff($resultSet[$i], $merged); $resultSet[$i] = Set::pushDiff($resultSet[$i], $merged);
unset($temp); unset($merged);
} }
} }
} }
@ -912,7 +918,7 @@ class DboSource extends DataSource {
function generateSelfAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet) { function generateSelfAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet) {
$alias = $association; $alias = $association;
if (empty($alias) && !empty($linkModel)) { if (empty($alias) && !empty($linkModel)) {
$alias = $linkModel->name; $alias = $linkModel->currentModel;
} }
if (!isset($queryData['selfJoin'])) { if (!isset($queryData['selfJoin'])) {
@ -928,7 +934,7 @@ class DboSource extends DataSource {
$model->escapeField($assocData['foreignKey']) => '{$__cakeIdentifier[' . "{$alias}.{$linkModel->primaryKey}" . ']__$}')) $model->escapeField($assocData['foreignKey']) => '{$__cakeIdentifier[' . "{$alias}.{$linkModel->primaryKey}" . ']__$}'))
), ),
'table' => $this->fullTableName($model), 'table' => $this->fullTableName($model),
'alias' => $model->name, 'alias' => $model->currentModel,
'limit' => $queryData['limit'], 'limit' => $queryData['limit'],
'offset' => $queryData['offset'], 'offset' => $queryData['offset'],
'conditions'=> $queryData['conditions'], 'conditions'=> $queryData['conditions'],
@ -995,10 +1001,10 @@ class DboSource extends DataSource {
$joinedOnSelf = false; $joinedOnSelf = false;
if (empty($queryData['fields'])) { if (empty($queryData['fields'])) {
$queryData['fields'] = $this->fields($model, $model->name); $queryData['fields'] = $this->fields($model, $model->currentModel);
} elseif (!empty($model->hasMany) && $model->recursive > -1) { } elseif (!empty($model->hasMany) && $model->recursive > -1) {
$assocFields = $this->fields($model, $model->name, array("{$model->name}.{$model->primaryKey}")); $assocFields = $this->fields($model, $model->currentModel, array("{$model->currentModel}.{$model->primaryKey}"));
$passedFields = $this->fields($model, $model->name, $queryData['fields']); $passedFields = $this->fields($model, $model->currentModel, $queryData['fields']);
if (count($passedFields) === 1) { if (count($passedFields) === 1) {
$match = strpos($passedFields[0], $assocFields[0]); $match = strpos($passedFields[0], $assocFields[0]);
@ -1021,7 +1027,7 @@ class DboSource extends DataSource {
return $this->buildStatement(array( return $this->buildStatement(array(
'fields' => array_unique($queryData['fields']), 'fields' => array_unique($queryData['fields']),
'table' => $this->fullTableName($model), 'table' => $this->fullTableName($model),
'alias' => $model->name, 'alias' => $model->currentModel,
'limit' => $queryData['limit'], 'limit' => $queryData['limit'],
'offset' => $queryData['offset'], 'offset' => $queryData['offset'],
'joins' => $queryData['joins'], 'joins' => $queryData['joins'],
@ -1032,7 +1038,7 @@ class DboSource extends DataSource {
} }
$alias = $association; $alias = $association;
if ($model->name == $linkModel->name) { if ($model->currentModel == $linkModel->currentModel) {
$joinedOnSelf = true; $joinedOnSelf = true;
} }
@ -1081,9 +1087,9 @@ class DboSource extends DataSource {
} }
} else { } else {
if ($type == 'hasOne') { if ($type == 'hasOne') {
$conditions = $this->__mergeConditions($assocData['conditions'], array("{$alias}.{$assocData['foreignKey']}" => '{$__cakeIdentifier[' . "{$model->name}.{$model->primaryKey}" . ']__$}')); $conditions = $this->__mergeConditions($assocData['conditions'], array("{$alias}.{$assocData['foreignKey']}" => '{$__cakeIdentifier[' . "{$model->currentModel}.{$model->primaryKey}" . ']__$}'));
} elseif ($type == 'belongsTo') { } elseif ($type == 'belongsTo') {
$conditions = $this->__mergeConditions($assocData['conditions'], array("{$model->name}.{$assocData['foreignKey']}" => '{$__cakeIdentifier[' . "{$alias}.{$linkModel->primaryKey}" . ']__$}')); $conditions = $this->__mergeConditions($assocData['conditions'], array("{$model->currentModel}.{$assocData['foreignKey']}" => '{$__cakeIdentifier[' . "{$alias}.{$linkModel->primaryKey}" . ']__$}'));
} }
$join = array( $join = array(
@ -1130,8 +1136,8 @@ class DboSource extends DataSource {
$joinFields = $joinFields->extract('{n}.name'); $joinFields = $joinFields->extract('{n}.name');
if (is_array($joinFields) && !empty($joinFields)) { if (is_array($joinFields) && !empty($joinFields)) {
$joinFields = $this->fields($model->{$assocData['with']}, $model->{$assocData['with']}->name, $joinFields); $joinFields = $this->fields($model->{$assocData['with']}, $model->{$assocData['with']}->currentModel, $joinFields);
$joinAssoc = $joinAlias = $model->{$assocData['with']}->name; $joinAssoc = $joinAlias = $model->{$assocData['with']}->currentModel;
} else { } else {
$joinFields = array(); $joinFields = array();
@ -1328,10 +1334,10 @@ class DboSource extends DataSource {
*/ */
function resolveKey($model, $key, $assoc = null) { function resolveKey($model, $key, $assoc = null) {
if (empty($assoc)) { if (empty($assoc)) {
$assoc = $model->name; $assoc = $model->currentModel;
} }
if (!strpos('.', $key)) { if (!strpos('.', $key)) {
return $this->name($model->name) . '.' . $this->name($key); return $this->name($model->currentModel) . '.' . $this->name($key);
} }
return $key; return $key;
} }
@ -1367,7 +1373,7 @@ class DboSource extends DataSource {
*/ */
function fields(&$model, $alias = null, $fields = array(), $quote = true) { function fields(&$model, $alias = null, $fields = array(), $quote = true) {
if (empty($alias)) { if (empty($alias)) {
$alias = $model->name; $alias = $model->currentModel;
} }
if (!is_array($fields)) { if (!is_array($fields)) {

View file

@ -74,7 +74,7 @@ class AclNode extends AppModel {
*/ */
function node($ref = null) { function node($ref = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
$type = $this->name; $type = $this->currentModel;
$prefix = $this->tablePrefix; $prefix = $this->tablePrefix;
$result = null; $result = null;
@ -119,13 +119,13 @@ class AclNode extends AppModel {
$result = $db->read($this, $queryData, -1); $result = $db->read($this, $queryData, -1);
} elseif (is_object($ref) && is_a($ref, 'Model')) { } elseif (is_object($ref) && is_a($ref, 'Model')) {
$ref = array('model' => $ref->name, 'foreign_key' => $ref->id); $ref = array('model' => $ref->currentModel, 'foreign_key' => $ref->id);
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) { } elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
$name = key($ref); $name = key($ref);
if (!ClassRegistry::isKeySet($name)) { if (!ClassRegistry::isKeySet($name)) {
if (!loadModel($name)) { if (!loadModel($name)) {
trigger_error("Model class '$name' not found in AclNode::node() when trying to bind {$this->name} object", E_USER_WARNING); trigger_error("Model class '$name' not found in AclNode::node() when trying to bind {$this->currentModel} object", E_USER_WARNING);
return null; return null;
} }
$model =& new $name(); $model =& new $name();

View file

@ -355,10 +355,10 @@ class Model extends Overloadable {
} }
if (isset($options['alias']) || !empty($options['alias'])) { if (isset($options['alias']) || !empty($options['alias'])) {
$this->currentModel = Inflector::underscore($options['alias']); $this->currentModel = $options['alias'];
unset($options); unset($options);
} else { } else {
$this->currentModel = Inflector::underscore($this->name); $this->currentModel = $this->name;
} }
ClassRegistry::addObject($this->currentModel, $this); ClassRegistry::addObject($this->currentModel, $this);
@ -697,7 +697,7 @@ class Model extends Overloadable {
} }
$this->alias[$assoc] = $this->{$assoc}->table; $this->alias[$assoc] = $this->{$assoc}->table;
$this->tableToModel[$this->{$assoc}->table] = $className; $this->tableToModel[$this->{$assoc}->table] = $assoc;
$this->modelToTable[$assoc] = $this->{$assoc}->table; $this->modelToTable[$assoc] = $this->{$assoc}->table;
} }
/** /**
@ -795,7 +795,7 @@ class Model extends Overloadable {
$sources = $db->listSources(); $sources = $db->listSources();
if (is_array($sources) && !in_array(low($this->tablePrefix . $tableName), array_map('low', $sources))) { if (is_array($sources) && !in_array(low($this->tablePrefix . $tableName), array_map('low', $sources))) {
return $this->cakeError('missingTable', array(array( return $this->cakeError('missingTable', array(array(
'className' => $this->name, 'className' => $this->currentModel,
'table' => $this->tablePrefix . $tableName))); 'table' => $this->tablePrefix . $tableName)));
} }
@ -825,24 +825,24 @@ class Model extends Overloadable {
if (is_array($one)) { if (is_array($one)) {
if (Set::countDim($one) == 1) { if (Set::countDim($one) == 1) {
$data = array($this->name => $one); $data = array($this->currentModel => $one);
} else { } else {
$data = $one; $data = $one;
} }
} else { } else {
$data = array($this->name => array($one => $two)); $data = array($this->currentModel => array($one => $two));
} }
foreach ($data as $n => $v) { foreach ($data as $n => $v) {
if (is_array($v)) { if (is_array($v)) {
foreach ($v as $x => $y) { foreach ($v as $x => $y) {
if (empty($this->whitelist) || (in_array($x, $this->whitelist) || $n !== $this->name)) { if (empty($this->whitelist) || (in_array($x, $this->whitelist) || $n !== $this->currentModel)) {
if (isset($this->validationErrors[$x])) { if (isset($this->validationErrors[$x])) {
unset ($this->validationErrors[$x]); unset ($this->validationErrors[$x]);
} }
if ($n === $this->name) { if ($n === $this->currentModel) {
if ($x === $this->primaryKey) { if ($x === $this->primaryKey) {
$this->id = $y; $this->id = $y;
} }
@ -991,7 +991,7 @@ class Model extends Overloadable {
} }
if ($this->id !== null && $this->id !== false) { if ($this->id !== null && $this->id !== false) {
$this->data = $this->find(array($this->name . '.' . $this->primaryKey => $id), $fields); $this->data = $this->find(array($this->currentModel . '.' . $this->primaryKey => $id), $fields);
return $this->data; return $this->data;
} else { } else {
return false; return false;
@ -1007,7 +1007,7 @@ class Model extends Overloadable {
*/ */
function field($name, $conditions = null, $order = null) { function field($name, $conditions = null, $order = null) {
if ($conditions === null && $this->id !== false) { if ($conditions === null && $this->id !== false) {
$conditions = array($this->name . '.' . $this->primaryKey => $this->id); $conditions = array($this->currentModel . '.' . $this->primaryKey => $this->id);
} }
if ($this->recursive >= 1) { if ($this->recursive >= 1) {
$recursive = -1; $recursive = -1;
@ -1017,8 +1017,8 @@ class Model extends Overloadable {
if ($data = $this->find($conditions, $name, $order, $recursive)) { if ($data = $this->find($conditions, $name, $order, $recursive)) {
if (strpos($name, '.') === false) { if (strpos($name, '.') === false) {
if (isset($data[$this->name][$name])) { if (isset($data[$this->currentModel][$name])) {
return $data[$this->name][$name]; return $data[$this->currentModel][$name];
} }
} else { } else {
$name = explode('.', $name); $name = explode('.', $name);
@ -1043,7 +1043,7 @@ class Model extends Overloadable {
* @return boolean True on success save * @return boolean True on success save
*/ */
function saveField($name, $value, $validate = false) { function saveField($name, $value, $validate = false) {
return $this->save(array($this->name => array($name => $value)), $validate, array($name)); return $this->save(array($this->currentModel => array($name => $value)), $validate, array($name));
} }
/** /**
* Saves model data to the database. * Saves model data to the database.
@ -1071,13 +1071,13 @@ class Model extends Overloadable {
} }
foreach (array('created', 'updated', 'modified') as $field) { foreach (array('created', 'updated', 'modified') as $field) {
if (array_key_exists($field, $this->data[$this->name]) && $this->data[$this->name][$field] === null) { if (array_key_exists($field, $this->data[$this->currentModel]) && $this->data[$this->currentModel][$field] === null) {
unset($this->data[$this->name][$field]); unset($this->data[$this->currentModel][$field]);
} }
} }
$exists = $this->exists(); $exists = $this->exists();
$fields = array_keys($this->data[$this->name]); $fields = array_keys($this->data[$this->currentModel]);
if (!$exists && $this->hasField('created') && !in_array('created', $fields)) { if (!$exists && $this->hasField('created') && !in_array('created', $fields)) {
$colType = am(array('formatter' => 'date'), $db->columns[$this->getColumnType('created')]); $colType = am(array('formatter' => 'date'), $db->columns[$this->getColumnType('created')]);
@ -1118,7 +1118,7 @@ class Model extends Overloadable {
if (isset($v[$n]) && $habtm > 0) { if (isset($v[$n]) && $habtm > 0) {
$joined[] = $v; $joined[] = $v;
} else { } else {
if ($n === $this->name) { if ($n === $this->currentModel) {
foreach (array('created', 'updated', 'modified') as $field) { foreach (array('created', 'updated', 'modified') as $field) {
if (array_key_exists($field, $v) && empty($v[$field])) { if (array_key_exists($field, $v) && empty($v[$field])) {
unset($v[$field]); unset($v[$field]);
@ -1150,7 +1150,7 @@ class Model extends Overloadable {
} else { } else {
foreach ($this->_tableInfo->value as $key => $value) { foreach ($this->_tableInfo->value as $key => $value) {
if (in_array($this->primaryKey, $value)) { if (in_array($this->primaryKey, $value)) {
if (empty($this->data[$this->name][$this->primaryKey]) && $this->_tableInfo->value[$key]['type'] === 'string' && $this->_tableInfo->value[$key]['length'] === 36) { if (empty($this->data[$this->currentModel][$this->primaryKey]) && $this->_tableInfo->value[$key]['type'] === 'string' && $this->_tableInfo->value[$key]['length'] === 36) {
$fields[] = $this->primaryKey; $fields[] = $this->primaryKey;
$values[] = String::uuid(); $values[] = String::uuid();
} }
@ -1343,7 +1343,7 @@ class Model extends Overloadable {
if (!empty($records)) { if (!empty($records)) {
foreach ($records as $record) { foreach ($records as $record) {
$model->delete($record[$model->name][$model->primaryKey]); $model->delete($record[$model->currentModel][$model->primaryKey]);
} }
} }
} }
@ -1368,7 +1368,7 @@ class Model extends Overloadable {
if (!empty($records)) { if (!empty($records)) {
foreach ($records as $record) { foreach ($records as $record) {
$model->delete($record[$model->name][$model->primaryKey]); $model->delete($record[$model->currentModel][$model->primaryKey]);
} }
} }
} else { } else {
@ -1393,7 +1393,7 @@ class Model extends Overloadable {
if (empty($records)) { if (empty($records)) {
return false; return false;
} }
$ids = Set::extract($records, "{n}.{$this->name}.{$this->primaryKey}"); $ids = Set::extract($records, "{n}.{$this->currentModel}.{$this->primaryKey}");
foreach ($ids as $id) { foreach ($ids as $id) {
$this->_deleteLinks($id); $this->_deleteLinks($id);
@ -1416,7 +1416,7 @@ class Model extends Overloadable {
if ($this->__exists !== null && $reset !== true) { if ($this->__exists !== null && $reset !== true) {
return $this->__exists; return $this->__exists;
} }
return $this->__exists = ($this->findCount(array($this->name . '.' . $this->primaryKey => $this->getID()), -1) > 0); return $this->__exists = ($this->findCount(array($this->currentModel . '.' . $this->primaryKey => $this->getID()), -1) > 0);
} }
/** /**
* Returns true if a record that meets given conditions exists * Returns true if a record that meets given conditions exists
@ -1519,8 +1519,8 @@ class Model extends Overloadable {
case 'count': case 'count':
if (isset($results[0][0]['count'])) { if (isset($results[0][0]['count'])) {
return intval($results[0][0]['count']); return intval($results[0][0]['count']);
} elseif (isset($results[0][$this->name]['count'])) { } elseif (isset($results[0][$this->currentModel]['count'])) {
return intval($results[0][$this->name]['count']); return intval($results[0][$this->currentModel]['count']);
} }
return false; return false;
break; break;
@ -1646,8 +1646,8 @@ class Model extends Overloadable {
unset($fields[$field]); unset($fields[$field]);
$field = $value; $field = $value;
if (isset($this->data[$this->name][$field])) { if (isset($this->data[$this->currentModel][$field])) {
$value = $this->data[$this->name][$field]; $value = $this->data[$this->currentModel][$field];
} else { } else {
$value = null; $value = null;
} }
@ -1655,7 +1655,7 @@ class Model extends Overloadable {
if (strpos($field, '.') === false) { if (strpos($field, '.') === false) {
unset($fields[$field]); unset($fields[$field]);
$fields[$this->name . '.' . $field] = $value; $fields[$this->currentModel . '.' . $field] = $value;
} }
} }
if ($or) { if ($or) {
@ -1690,11 +1690,11 @@ class Model extends Overloadable {
$sizeOf = sizeof($data); $sizeOf = sizeof($data);
for ($ii = 0; $ii < $sizeOf; $ii++) { for ($ii = 0; $ii < $sizeOf; $ii++) {
if (($data[$ii][$this->name]['parent_id'] == $root) || (($root === null) && ($data[$ii][$this->name]['parent_id'] == '0'))) { if (($data[$ii][$this->currentModel]['parent_id'] == $root) || (($root === null) && ($data[$ii][$this->currentModel]['parent_id'] == '0'))) {
$tmp = $data[$ii]; $tmp = $data[$ii];
if (isset($data[$ii][$this->name][$this->primaryKey])) { if (isset($data[$ii][$this->currentModel][$this->primaryKey])) {
$tmp['children'] = $this->__doThread($data, $data[$ii][$this->name][$this->primaryKey]); $tmp['children'] = $this->__doThread($data, $data[$ii][$this->currentModel][$this->primaryKey]);
} else { } else {
$tmp['children'] = null; $tmp['children'] = null;
} }
@ -1790,8 +1790,8 @@ class Model extends Overloadable {
return $this->validationErrors; return $this->validationErrors;
} }
if (isset($data[$this->name])) { if (isset($data[$this->currentModel])) {
$data = $data[$this->name]; $data = $data[$this->currentModel];
} }
$Validation = new Validation(); $Validation = new Validation();
@ -1939,11 +1939,11 @@ class Model extends Overloadable {
} }
if ($keyPath == null) { if ($keyPath == null) {
$keyPath = '{n}.' . $this->name . '.' . $this->primaryKey; $keyPath = '{n}.' . $this->currentModel . '.' . $this->primaryKey;
} }
if ($valuePath == null) { if ($valuePath == null) {
$valuePath = '{n}.' . $this->name . '.' . $this->displayField; $valuePath = '{n}.' . $this->currentModel . '.' . $this->displayField;
} }
return Set::combine($result, $keyPath, $valuePath, $groupPath); return Set::combine($result, $keyPath, $valuePath, $groupPath);
@ -1956,7 +1956,7 @@ class Model extends Overloadable {
*/ */
function escapeField($field = null, $alias = null) { function escapeField($field = null, $alias = null) {
if (empty($alias)) { if (empty($alias)) {
$alias = $this->name; $alias = $this->currentModel;
} }
if (empty($field)) { if (empty($field)) {
$field = $this->primaryKey; $field = $this->primaryKey;
@ -2054,7 +2054,7 @@ class Model extends Overloadable {
} }
if (empty($db) || $db == null || !is_object($db)) { if (empty($db) || $db == null || !is_object($db)) {
return $this->cakeError('missingConnection', array(array('className' => $this->name))); return $this->cakeError('missingConnection', array(array('className' => $this->currentModel)));
} }
} }
/** /**
@ -2176,7 +2176,7 @@ class Model extends Overloadable {
function _clearCache($type = null) { function _clearCache($type = null) {
if ($type === null) { if ($type === null) {
if (Configure::read('Cache.check') === true) { if (Configure::read('Cache.check') === true) {
$assoc[] = strtolower(Inflector::pluralize($this->name)); $assoc[] = strtolower(Inflector::pluralize($this->currentModel));
foreach ($this->__associations as $key => $association) { foreach ($this->__associations as $key => $association) {
foreach ($this->$association as $key => $className) { foreach ($this->$association as $key => $className) {
$check = strtolower(Inflector::pluralize($className['className'])); $check = strtolower(Inflector::pluralize($className['className']));

View file

@ -787,13 +787,13 @@ class View extends Object {
$cache->view = &$this; $cache->view = &$this;
} }
$cache->base = $this->base; $cache->base = $this->base;
$cache->here = $this->here; $cache->here = $this->here;
$cache->helpers = $this->helpers; $cache->helpers = $this->helpers;
$cache->action = $this->action; $cache->action = $this->action;
$cache->controllerName = $this->name; $cache->controllerName = $this->name;
$cache->layout = $this->layout; $cache->layout = $this->layout;
$cache->cacheAction = $this->cacheAction; $cache->cacheAction = $this->cacheAction;
$cache->cache($___viewFn, $out, $cached); $cache->cache($___viewFn, $out, $cached);
} }
} }

View file

@ -631,7 +631,7 @@ class DboSourceTest extends UnitTestCase {
$linkModel =& $this->model->Category2->{$assoc}; $linkModel =& $this->model->Category2->{$assoc};
$external = isset($assocData['external']); $external = isset($assocData['external']);
if ($this->model->Category2->name == $linkModel->name && $type != 'hasAndBelongsToMany' && $type != 'hasMany') { if ($this->model->Category2->currentModel == $linkModel->currentModel && $type != 'hasAndBelongsToMany' && $type != 'hasMany') {
$result = $this->db->generateSelfAssociationQuery($this->model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null); $result = $this->db->generateSelfAssociationQuery($this->model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
$this->assertTrue($result); $this->assertTrue($result);
} else { } else {

View file

@ -570,7 +570,7 @@ class ModelTest extends CakeTestCase {
function testIdentity() { function testIdentity() {
$this->model =& new Test(); $this->model =& new Test();
$result = $this->model->name; $result = $this->model->currentModel;
$expected = 'Test'; $expected = 'Test';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
@ -2536,35 +2536,56 @@ class ModelTest extends CakeTestCase {
$result = $this->model->findAll(); $result = $this->model->findAll();
$expected = array(array('Apple' => array ( $expected = array(array('Apple' => array (
'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04','modified' => '2006-12-01 13:31:26'), 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => 2,'apple_id' => 2,'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Sample' => array('id' => '','apple_id' => '','name' => ''), 'Child' => array(
'Child' => array(array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01','modified' => '2006-11-30 18:38:10', array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')))), array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' =>'', 'apple_id' => '', 'name' => ''),
'Child' => array(
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))))),
array('Apple' => array( array('Apple' => array(
'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Parent' => array ('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01','modified' => '2006-11-30 18:38:10'), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array()), 'Sample' => array(),
'Child' => array(
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2',
'Apple' => array ('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10')), 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10')),
'Child' => array(array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'Child' => array(
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26',
'Sample' => array()), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'Sample' => array(),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'Child' => array(
'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')), array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3')))), 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3'),
'Child' => array(
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'))))),
array('Apple' => array( array('Apple' => array(
'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'), 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1',
'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24')), 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24')),
'Child' => array()), 'Child' => array()),
@ -2572,114 +2593,163 @@ class ModelTest extends CakeTestCase {
'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), 'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3', 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3',
'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36')), 'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36')),
'Child' => array(array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'Child' => array(
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39',
'Sample' => array()))), 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Sample' => array(),
'Child' => array(
array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'))))),
array('Apple' => array( array('Apple' => array(
'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), 'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16',
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')), 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4'),
'Child' => array(
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4', 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4',
'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16')), 'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16')),
'Child' => array(array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'Child' => array(
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16',
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')))), 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4'),
'Child' => array(
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))))),
array('Apple' => array( array('Apple' => array(
'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'), 'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array( 'id' => 3, 'apple_id' => 6, 'name' => 'sample3')), 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3'),
'Child' => array(
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''),
'Child' => array(array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'Child' => array(
'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'), array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21',
'Sample' => array()))), 'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
'Sample' => array()))),
array('Apple' => array( array('Apple' => array(
'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'), 'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'),
'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39',
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Sample' => array()), 'Sample' => array(),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), 'Child' => array(
'Child' => array())); array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''),
'Child' => array()));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->model =& new Apple();
$this->model->recursive = 2;
$result = $this->model->Parent->unbindModel(array('hasOne' => array('Sample'))); $result = $this->model->Parent->unbindModel(array('hasOne' => array('Sample')));
$this->assertTrue($result); $this->assertTrue($result);
$result = $this->model->findAll(); $result = $this->model->findAll();
$expected = array(array('Apple' => array ( $expected = array(array('Apple' => array (
'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04','modified' => '2006-12-01 13:31:26'), 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26')),
'Sample' => array('id' => '','apple_id' => '','name' => ''),
'Child' => array(array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01','modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')))), 'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' =>'', 'apple_id' => '', 'name' => ''),
'Child' => array(
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))))),
array('Apple' => array( array('Apple' => array(
'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Parent' => array ('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01','modified' => '2006-11-30 18:38:10')), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Child' => array(
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2',
'Apple' => array ('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10')), 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10')),
'Child' => array(array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'Child' => array(
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26',
'Sample' => array()), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'Sample' => array(),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'Child' => array(
'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')), array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3')))), 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3'),
'Child' => array(
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'))))),
array('Apple' => array( array('Apple' => array(
'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'), 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26')), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1',
'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24')), 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24')),
'Child' => array()), 'Child' => array()),
array('Apple' => array( array('Apple' => array(
'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), 'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26')), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3', 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3',
'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36')), 'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36')),
'Child' => array(array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'Child' => array(
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39',
'Sample' => array()))), 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Sample' => array(),
'Child' => array(
array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'))))),
array('Apple' => array( array('Apple' => array(
'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), 'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16',
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16')), 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Child' => array(
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4', 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4',
'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16')), 'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16')),
'Child' => array(array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'Child' => array(
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16',
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')))), 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4'),
'Child' => array(
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))))),
array('Apple' => array( array('Apple' => array(
'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'), 'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10')), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Child' => array(
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''),
'Child' => array(array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'Child' => array(
'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'), array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21',
'Sample' => array()))), 'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
'Sample' => array()))),
array('Apple' => array( array('Apple' => array(
'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'), 'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'),
'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39',
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36')), 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), 'Child' => array(
'Child' => array())); array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''),
'Child' => array()));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->model =& new Apple();
$this->model->recursive = 2;
$result = $this->model->Parent->unbindModel(array('hasOne' => array('Sample'))); $result = $this->model->Parent->unbindModel(array('hasOne' => array('Sample')));
$this->assertTrue($result); $this->assertTrue($result);
@ -2688,49 +2758,66 @@ class ModelTest extends CakeTestCase {
$result = $this->model->findAll(); $result = $this->model->findAll();
$expected = array(array('Apple' => array ( $expected = array(array('Apple' => array (
'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04','modified' => '2006-12-01 13:31:26'), 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26')), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => '','apple_id' => '','name' => '')), 'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' =>'', 'apple_id' => '', 'name' => '')),
array('Apple' => array( array('Apple' => array(
'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Parent' => array ('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01','modified' => '2006-11-30 18:38:10')), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Child' => array(
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2',
'Apple' => array ('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))), 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
array('Apple' => array( array('Apple' => array(
'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'), 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26')), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1',
'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'))), 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'))),
array('Apple' => array( array('Apple' => array(
'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), 'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26')), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3', 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3',
'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))), 'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
array('Apple' => array( array('Apple' => array(
'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), 'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16',
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16')), 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Child' => array(
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4', 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4',
'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))), 'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))),
array('Apple' => array( array('Apple' => array(
'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'), 'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10')), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Child' => array(
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')), 'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')),
array('Apple' => array( array('Apple' => array(
'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'), 'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'),
'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39',
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36')), 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''))); 'Child' => array(
array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->model =& new Apple();
$this->model->recursive = 2;
$result = $this->model->unbindModel(array('hasMany' => array('Child'))); $result = $this->model->unbindModel(array('hasMany' => array('Child')));
$this->assertTrue($result); $this->assertTrue($result);
@ -2739,47 +2826,67 @@ class ModelTest extends CakeTestCase {
$result = $this->model->findAll(); $result = $this->model->findAll();
$expected = array(array('Apple' => array ( $expected = array(array('Apple' => array (
'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04','modified' => '2006-12-01 13:31:26'), 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => 2,'apple_id' => 2,'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Sample' => array('id' => '','apple_id' => '','name' => '')), 'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' =>'', 'apple_id' => '', 'name' => '')),
array('Apple' => array( array('Apple' => array(
'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Parent' => array ('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01','modified' => '2006-11-30 18:38:10'), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array()), 'Sample' => array(),
'Child' => array(
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')),
array('Apple' => array( array('Apple' => array(
'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'), 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')), 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')),
array('Apple' => array( array('Apple' => array(
'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), 'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'), 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3')), 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3')),
array('Apple' => array( array('Apple' => array(
'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), 'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16',
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')), 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4'),
'Child' => array(
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')), 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')),
array('Apple' => array( array('Apple' => array(
'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'), 'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36',
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Sample' => array( 'id' => 3, 'apple_id' => 6, 'name' => 'sample3')), 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3'),
'Child' => array(
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')), 'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')),
array('Apple' => array( array('Apple' => array(
'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'), 'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'),
'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39',
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Sample' => array()), 'Sample' => array(),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''))); 'Child' => array(
array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->model->Parent->unbindModel(array('belongsTo' => array('Parent'))); $result = $this->model->Parent->unbindModel(array('belongsTo' => array('Parent')));
@ -2790,44 +2897,64 @@ class ModelTest extends CakeTestCase {
$result = $this->model->findAll(); $result = $this->model->findAll();
$expected = array(array('Apple' => array ( $expected = array(array('Apple' => array (
'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04','modified' => '2006-12-01 13:31:26'), 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Sample' => array('id' => 2,'apple_id' => 2,'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Sample' => array('id' => '','apple_id' => '','name' => '')), 'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' =>'', 'apple_id' => '', 'name' => '')),
array('Apple' => array( array('Apple' => array(
'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'), 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
'Parent' => array ('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26',
'Sample' => array()), 'Sample' => array(),
'Child' => array(
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2',
'Apple' => array ('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))), 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'))),
array('Apple' => array( array('Apple' => array(
'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'), 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Sample' => array( 'id' => 2, 'apple_id' => 2, 'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1',
'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'))), 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'))),
array('Apple' => array( array('Apple' => array(
'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'), 'id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10',
'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
'Child' => array(
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3', 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3',
'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))), 'Apple' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'))),
array('Apple' => array( array('Apple' => array(
'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'), 'id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'Parent' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16',
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')), 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4'),
'Child' => array(
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))),
'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4', 'Sample' => array('id' => 4, 'apple_id' => 7, 'name' => 'sample4',
'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))), 'Apple' => array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'))),
array('Apple' => array( array('Apple' => array(
'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'), 'id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'Parent' => array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36',
'Sample' => array( 'id' => 3, 'apple_id' => 6, 'name' => 'sample3')), 'Sample' => array('id' => 3, 'apple_id' => 6, 'name' => 'sample3'),
'Child' => array(
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')), 'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')),
array('Apple' => array( array('Apple' => array(
'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'), 'id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'),
'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'Parent' => array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39',
'Sample' => array()), 'Sample' => array(),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''))); 'Child' => array(
array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21'))),
'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }

View file

@ -127,10 +127,10 @@ class CakeTestCase extends UnitTestCase {
foreach ($classRegistry->__map as $key => $name) { foreach ($classRegistry->__map as $key => $name) {
$object =& $classRegistry->getObject(Inflector::camelize($key)); $object =& $classRegistry->getObject(Inflector::camelize($key));
if (is_subclass_of($object, 'Model') && ((is_array($params['fixturize']) && in_array($object->name, $params['fixturize'])) || $params['fixturize'] === true)) { if (is_subclass_of($object, 'Model') && ((is_array($params['fixturize']) && in_array($object->currentModel, $params['fixturize'])) || $params['fixturize'] === true)) {
$models[$object->name] = array ( $models[$object->currentModel] = array (
'table' => $object->table, 'table' => $object->table,
'model' => $object->name, 'model' => $object->currentModel,
'key' => Inflector::camelize($key) 'key' => Inflector::camelize($key)
); );
} }

View file

@ -91,7 +91,7 @@ class CakeTestFixture extends Object {
$query = array( $query = array(
'fields' => array_keys($this->fields), 'fields' => array_keys($this->fields),
'table' => $db->name($model->table), 'table' => $db->name($model->table),
'alias' => $model->name, 'alias' => $model->currentModel,
'conditions' => array(), 'conditions' => array(),
'order' => null, 'order' => null,
'limit' => null 'limit' => null
@ -101,10 +101,10 @@ class CakeTestFixture extends Object {
$query['fields'][$index] = $db->name($query['alias']) . '.' . $db->name($field); $query['fields'][$index] = $db->name($query['alias']) . '.' . $db->name($field);
} }
$records = $db->fetchAll($db->buildStatement($query, $model), false, $model->name); $records = $db->fetchAll($db->buildStatement($query, $model), false, $model->currentModel);
if ($records !== false && !empty($records)) { if ($records !== false && !empty($records)) {
$this->records = Set::extract($records, '{n}.' . $model->name); $this->records = Set::extract($records, '{n}.' . $model->currentModel);
} }
} }
} }