-
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
Conversation
if ($success) { | ||
if (!empty($joined)) { | ||
$this->_saveMulti($joined, $this->id, $db); | ||
} else if ($count === 0) { |
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
if ($success) { | ||
if ($count > 0) { | ||
if (!empty($this->data)) { | ||
if ($created) { |
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.
I wonder if those 4 nested levels of ifs are really necessary..
at least the last two could probably be combined.
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.
Yeah looks a bit too much
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.
How about this:
$this->whitelist = $_whitelist;
if (!$success) {
return $success;
}
if ($count > 0) {
if (!empty($this->data) && $created) {
$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 (!empty($this->data)) {
$success = $this->data;
}
$this->_clearCache();
$this->validationErrors = array();
$this->data = false;
return $success;
this new commit should hopefully allow better readability. |
Erf... each time I fix a bug, I find another one...
I will restore the previous behaviour, but that will imply that user will only be able to retrieve 'true/false' instead of the array of saved data. |
Seems reasonable to me. |
when do you think this will be merged ? I was thinking I will wait for the merge and rebase my branch used for #3516 to resolve the remaining problems... |
2.6 fix save() with habtm returning error
bug found while handling PR 3516.
#3516
$Model->save($data) may return false if the given $data to save does not contain some $Model related data.