Skip to content

Commit

Permalink
Fix exists usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 18, 2017
1 parent a662185 commit 0882feb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Model/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Cake\Validation\Validator;
use Exception;
use InvalidArgumentException;
use RuntimeException;

class Table extends CoreTable {

Expand Down Expand Up @@ -343,12 +344,17 @@ public function fieldByConditions($name, array $conditions = [], array $customOp
/**
* 2.x shim for exists() and primary key.
*
* @deprecated Not usable as array, only for single primary keys. Use exists() directly.
* @param int $id
* @return bool
*/
public function existsById($id) {
$primaryKey = $this->primaryKey();
if (is_array($primaryKey)) {
throw new RuntimeException('Not supported with multiple primary keys');
}
$conditions = [
$this->primaryKey() => $id
$primaryKey => $id
];
return parent::exists($conditions);
}
Expand Down

0 comments on commit 0882feb

Please sign in to comment.