Adding fix from #1215

Fixes issues with saving HABTM

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3478 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-09-14 18:37:51 +00:00
parent 27fc6bced9
commit 678ec860a1
2 changed files with 15 additions and 11 deletions

View file

@ -437,7 +437,8 @@ class DataSource extends Object{
return $model->name . $key; return $model->name . $key;
} }
/** /**
* Enter description here... The special {n}, as seen in the Model::generateList method, is taken care of here. * Gets a value from an array or object.
* The special {n}, as seen in the Model::generateList method, is taken care of here.
* *
* @param array $data * @param array $data
* @param mixed $path As an array, or as a dot-separated string. * @param mixed $path As an array, or as a dot-separated string.

View file

@ -1039,24 +1039,27 @@ class Model extends Overloadable {
} }
if (!empty($newValues)) { if (!empty($newValues)) {
$newValue[] = $newValues; $newValue[$assoc] = $newValues;
unset($newValues); unset($newValues);
} else {
$newValue[$assoc] = array();
} }
} }
} }
$total = count($joinTable); $total = count($joinTable);
for($count = 0; $count < $total; $count++) { if(is_array($newValue)){
$db =& ConnectionManager::getDataSource($this->useDbConfig); foreach ($newValue as $loopAssoc=>$val) {
$table = $db->name($db->fullTableName($joinTable[$count])); $db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->execute("DELETE FROM {$table} WHERE {$mainKey[$count]} = '{$id}'"); $table = $db->name($db->fullTableName($joinTable[$loopAssoc]));
$db->execute("DELETE FROM {$table} WHERE {$mainKey[$loopAssoc]} = '{$id}'");
if (!empty($newValue[$count])) { if (!empty($newValue[$loopAssoc])) {
$secondCount = count($newValue[$count]); $secondCount = count($newValue[$loopAssoc]);
for($x = 0; $x < $secondCount; $x++) {
for($x = 0; $x < $secondCount; $x++) { $db->execute("INSERT INTO {$table} ({$fields[$loopAssoc]}) VALUES {$newValue[$loopAssoc][$x]}");
$db->execute("INSERT INTO {$table} ({$fields[$count]}) VALUES {$newValue[$count][$x]}"); }
} }
} }
} }