mirror of
https://github.com/avecms/AVE.cms.git
synced 2026-08-01 00:45:44 +00:00
1.4 KiB
1.4 KiB
SoftDelete - soft deletion
App\Helpers\SoftDelete - generates fragments of SQL conditions for two accepted in
draft soft removal conventions:
- boolean flag:
is_deleted/ legacydeleted('1'/'0'); - nullable label:
deleted_at(NULL= active).
use App\Helpers\SoftDelete;
Methods
###active($alias = null, $column = 'deleted_at')
The condition “record not deleted”.
$sql = 'SELECT * FROM ' . $t . ' u WHERE ' . SoftDelete::active('u');
// ... u.deleted_at IS NULL
###deleted($alias = null, $column = 'deleted_at')
The “record deleted” condition.
documentActive($alias = null) / documentDeleted($alias = null)
Conditions according to the convention documents (document_deleted).
$where .= ' AND ' . SoftDelete::documentActive('d');
// ... d.document_deleted != '1'
###condition($alias, $column, $deleted)
Arbitrary condition: collect for a specific column.
Recipe
use App\Content\ContentTables;
use App\Helpers\SoftDelete;
$t = ContentTables::table('documents');
$rows = DB::query(
'SELECT * FROM ' . $t . ' d WHERE d.rubric_id = %i AND ' . SoftDelete::documentActive('d'),
$rubricId
)->getAll();
Returns string - substituted directly into
WHERE. Values are not parameterizable (these are static conditions), user input does not fall into them.