Skip to content

Commit

Permalink
Merge pull request #12692 from bancer/model-exists-without-id
Browse files Browse the repository at this point in the history
Add model id to all `exists()` method calls
  • Loading branch information
markstory committed Nov 2, 2018
2 parents 89005c4 + 58ebf6a commit b1a93df
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
Expand Up @@ -131,12 +131,11 @@
* @return void
*/
public function <?php echo $admin; ?>delete($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
}
$this->request->allowMethod('post', 'delete');
if ($this-><?php echo $currentModelName; ?>->delete()) {
if ($this-><?php echo $currentModelName; ?>->delete($id)) {
<?php if ($wannaUseSession): ?>
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -225,7 +225,7 @@ public function beforeSave(Model $Model, $options = array()) {
}
$parentIsSet = array_key_exists($parent, $Model->data[$Model->alias]);

if (!$Model->id || !$Model->exists()) {
if (!$Model->id || !$Model->exists($Model->getID())) {
if ($parentIsSet && $Model->data[$Model->alias][$parent]) {
$parentNode = $this->_getNode($Model, $Model->data[$Model->alias][$parent]);
if (!$parentNode) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -2547,7 +2547,7 @@ public function defaultConditions(Model $Model, $conditions, $useAlias = true) {
if (!empty($conditions)) {
return $conditions;
}
$exists = $Model->exists();
$exists = $Model->exists($Model->getID());
if (!$exists && ($conditions !== null || !empty($Model->__safeUpdateMode))) {
return false;
} elseif (!$exists) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Model.php
Expand Up @@ -1824,7 +1824,7 @@ protected function _doSave($data = null, $options = array()) {
}
}

$exists = $this->exists();
$exists = $this->exists($this->getID());
$dateFields = array('modified', 'updated');

if (!$exists) {
Expand Down Expand Up @@ -2696,7 +2696,7 @@ public function delete($id = null, $cascade = true) {
return false;
}

if (!$this->exists()) {
if (!$this->exists($this->getID())) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/ModelValidator.php
Expand Up @@ -257,7 +257,7 @@ public function errors($options = array()) {
}
}

$exists = $model->exists();
$exists = $model->exists($model->getID());
$methods = $this->getMethods();
$fields = $this->_validationList($fieldList);

Expand Down
Expand Up @@ -77,12 +77,11 @@
* @return void
*/
public function delete($id = null) {
$this->BakeArticle->id = $id;
if (!$this->BakeArticle->exists()) {
if (!$this->BakeArticle->exists($id)) {
throw new NotFoundException(__('Invalid bake article'));
}
$this->request->allowMethod('post', 'delete');
if ($this->BakeArticle->delete()) {
if ($this->BakeArticle->delete($id)) {
$this->Flash->success(__('The bake article has been deleted.'));
} else {
$this->Flash->error(__('The bake article could not be deleted. Please, try again.'));
Expand Down
Expand Up @@ -71,12 +71,11 @@
* @return void
*/
public function delete($id = null) {
$this->BakeArticle->id = $id;
if (!$this->BakeArticle->exists()) {
if (!$this->BakeArticle->exists($id)) {
throw new NotFoundException(__('Invalid bake article'));
}
$this->request->allowMethod('post', 'delete');
if ($this->BakeArticle->delete()) {
if ($this->BakeArticle->delete($id)) {
return $this->flash(__('The bake article has been deleted.'), array('action' => 'index'));
} else {
return $this->flash(__('The bake article could not be deleted. Please, try again.'), array('action' => 'index'));
Expand Down

0 comments on commit b1a93df

Please sign in to comment.