Last active
February 5, 2016 15:27
-
-
Save garethellis36/c03c1ddac01540d88392 to your computer and use it in GitHub Desktop.
Possible improvement to CakePHP AppModel::updateAll() ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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