mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
fix save with habtm returning false
This commit is contained in:
parent
2546b79c62
commit
a8e410ee20
2 changed files with 22 additions and 18 deletions
|
@ -1784,7 +1784,7 @@ class Model extends Object implements CakeEventListener {
|
||||||
if (empty($this->data[$this->alias][$this->primaryKey])) {
|
if (empty($this->data[$this->alias][$this->primaryKey])) {
|
||||||
unset($this->data[$this->alias][$this->primaryKey]);
|
unset($this->data[$this->alias][$this->primaryKey]);
|
||||||
}
|
}
|
||||||
$fields = $values = array();
|
$joined = $fields = $values = array();
|
||||||
|
|
||||||
foreach ($this->data as $n => $v) {
|
foreach ($this->data as $n => $v) {
|
||||||
if (isset($this->hasAndBelongsToMany[$n])) {
|
if (isset($this->hasAndBelongsToMany[$n])) {
|
||||||
|
@ -1843,15 +1843,16 @@ class Model extends Object implements CakeEventListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($joined) && $success === true) {
|
if ($success) {
|
||||||
|
if (!empty($joined)) {
|
||||||
$this->_saveMulti($joined, $this->id, $db);
|
$this->_saveMulti($joined, $this->id, $db);
|
||||||
}
|
} else if ($count === 0) {
|
||||||
|
|
||||||
if ($success && $count === 0) {
|
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($success && $count > 0) {
|
if ($success) {
|
||||||
|
if ($count > 0) {
|
||||||
if (!empty($this->data)) {
|
if (!empty($this->data)) {
|
||||||
if ($created) {
|
if ($created) {
|
||||||
$this->data[$this->alias][$this->primaryKey] = $this->id;
|
$this->data[$this->alias][$this->primaryKey] = $this->id;
|
||||||
|
@ -1862,6 +1863,7 @@ class Model extends Object implements CakeEventListener {
|
||||||
$event = new CakeEvent('Model.afterSave', $this, array($created, $options));
|
$event = new CakeEvent('Model.afterSave', $this, array($created, $options));
|
||||||
$this->getEventManager()->dispatch($event);
|
$this->getEventManager()->dispatch($event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($this->data)) {
|
if (!empty($this->data)) {
|
||||||
$success = $this->data;
|
$success = $this->data;
|
||||||
|
|
|
@ -1824,7 +1824,9 @@ class ModelWriteTest extends BaseModelTest {
|
||||||
|
|
||||||
$data = array('Item' => array('Item' => array(1, 2)));
|
$data = array('Item' => array('Item' => array(1, 2)));
|
||||||
$TestModel->id = 2;
|
$TestModel->id = 2;
|
||||||
$TestModel->save($data);
|
$result = $TestModel->save($data);
|
||||||
|
$this->assertTrue((bool)$result);
|
||||||
|
|
||||||
$result = $TestModel->findById(2);
|
$result = $TestModel->findById(2);
|
||||||
$result['Item'] = Hash::sort($result['Item'], '{n}.id', 'asc');
|
$result['Item'] = Hash::sort($result['Item'], '{n}.id', 'asc');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
|
Loading…
Reference in a new issue