Skip to content

Instantly share code, notes, and snippets.

@garethellis36
Last active February 5, 2016 15:27
Show Gist options
  • Save garethellis36/c03c1ddac01540d88392 to your computer and use it in GitHub Desktop.
Save garethellis36/c03c1ddac01540d88392 to your computer and use it in GitHub Desktop.
Possible improvement to CakePHP AppModel::updateAll() ?
//Add to app/Model/AppModel.php
public function updateAll($fields, $conditions = true)
{
$fields = array_map([$this, "quoteString"], $fields);
if (is_array($conditions)) {
$conditions = array_map([$this, "quoteString"], $conditions);
}
parent::updateAll($fields, $conditions);
}
protected function quoteString($value)
{
//don't quote integers/booleans etc
if (!is_string($value)) {
return $value;
}
$db = $this->getDataSource();
return $db->value($value, 'string');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment