*
* @return boolean|array was the delete successful? When $in_process is set: deletion data
*/
- public static function delete($table, array $conditions, $in_process = false, array &$callstack = [])
+ public static function delete($table, array $conditions, array $options = [], $in_process = false, array &$callstack = [])
{
if (empty($table) || empty($conditions)) {
logger('Table and conditions have to be set');
$commands[$key] = ['table' => $table, 'conditions' => $conditions];
+ $cascade = defaults($options, 'cascade', true);
+
// To speed up the whole process we cache the table relations
- if (count(self::$relation) == 0) {
+ if ($cascade && count(self::$relation) == 0) {
self::buildRelationData();
}
if ((count($conditions) == 1) && ($field == array_keys($conditions)[0])) {
foreach ($rel_def AS $rel_table => $rel_fields) {
foreach ($rel_fields AS $rel_field) {
- $retval = self::delete($rel_table, [$rel_field => array_values($conditions)[0]], true, $callstack);
+ $retval = self::delete($rel_table, [$rel_field => array_values($conditions)[0]], $options, true, $callstack);
$commands = array_merge($commands, $retval);
}
}
while ($row = self::fetch($data)) {
// Now we accumulate the delete commands
- $retval = self::delete($table, [$field => $row[$field]], true, $callstack);
+ $retval = self::delete($table, [$field => $row[$field]], $options, true, $callstack);
$commands = array_merge($commands, $retval);
}