Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Created December 30, 2014 09:41
Show Gist options
  • Save lorenzo/e07ff5ef4a916f19ed2a to your computer and use it in GitHub Desktop.
Save lorenzo/e07ff5ef4a916f19ed2a to your computer and use it in GitHub Desktop.
/**
* Override default updateAll to workaround forced joins
*
* @return void
*/
public function updateAll($fields, $conditions = true) {
$name = $this->name;
$this->name = '_model_';
try {
$result = parent::updateAll($fields, $conditions);
} catch (Exception $e) {
$this->name = $name;
throw $e;
}
$this->name = $name;
return $result;
}
/**
* Override default deleteAll to workaround forced joins
*
* @return void
*/
public function deleteAll($conditions, $dependent = true, $callbacks = false) {
$associated = [];
foreach ($this->getAssociated() as $model => $type) {
$associated[$type][] = $model;
}
$this->unbindModel($associated);
return parent::deleteAll($conditions, $dependent, $callbacks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment