-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.6 fix save() with habtm returning error #3590
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1784,7 +1784,7 @@ public function save($data = null, $validate = true, $fieldList = array()) { | |
if (empty($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) { | ||
if (isset($this->hasAndBelongsToMany[$n])) { | ||
|
@@ -1843,24 +1843,26 @@ public function save($data = null, $validate = true, $fieldList = array()) { | |
} | ||
} | ||
|
||
if (!empty($joined) && $success === true) { | ||
$this->_saveMulti($joined, $this->id, $db); | ||
} | ||
|
||
if ($success && $count === 0) { | ||
$success = false; | ||
if ($success) { | ||
if (!empty($joined)) { | ||
$this->_saveMulti($joined, $this->id, $db); | ||
} else if ($count === 0) { | ||
$success = false; | ||
} | ||
} | ||
|
||
if ($success && $count > 0) { | ||
if (!empty($this->data)) { | ||
if ($created) { | ||
$this->data[$this->alias][$this->primaryKey] = $this->id; | ||
if ($success) { | ||
if ($count > 0) { | ||
if (!empty($this->data)) { | ||
if ($created) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if those 4 nested levels of ifs are really necessary.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah looks a bit too much There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about this:
|
||
$this->data[$this->alias][$this->primaryKey] = $this->id; | ||
} | ||
} | ||
} | ||
|
||
if ($options['callbacks'] === true || $options['callbacks'] === 'after') { | ||
$event = new CakeEvent('Model.afterSave', $this, array($created, $options)); | ||
$this->getEventManager()->dispatch($event); | ||
if ($options['callbacks'] === true || $options['callbacks'] === 'after') { | ||
$event = new CakeEvent('Model.afterSave', $this, array($created, $options)); | ||
$this->getEventManager()->dispatch($event); | ||
} | ||
} | ||
|
||
if (!empty($this->data)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elseif