[COMPONENT][Attachment] Delete related

This commit is contained in:
2021-12-10 02:38:04 +00:00
parent 5f167517ad
commit dcc867dad7
5 changed files with 180 additions and 2 deletions

View File

@@ -19,6 +19,8 @@
namespace Component\Attachment\Entity;
use App\Core\Cache;
use App\Core\DB\DB;
use App\Core\Entity;
use DateTimeInterface;
@@ -92,6 +94,53 @@ class AttachmentToNote extends Entity
// @codeCoverageIgnoreEnd
// }}} Autocode
/**
* @param int $note_id
* @param int $attachment_id
* @return mixed
*/
public static function removeWhere(int $note_id, int $attachment_id): mixed
{
return DB::dql(
<<<'EOF'
DELETE FROM attachment_to_note atn
WHERE (atn.attachment_id = :attachment_id
OR atn.note_id = :note_id)
EOF,
['note_id' => $note_id, 'attachment_id' => $attachment_id],
);
}
/**
* @param int $note_id
* @return mixed
*/
public static function removeWhereNoteId(int $note_id): mixed
{
return DB::dql(
<<<'EOF'
DELETE FROM attachment_to_note atn
WHERE atn.note_id = :note_id
EOF,
['note_id' => $note_id],
);
}
/**
* @param int $attachment_id
* @return mixed
*/
public static function removeWhereAttachmentId(int $attachment_id): mixed
{
return DB::dql(
<<<'EOF'
DELETE FROM attachment_to_note atn
WHERE atn.attachment_id = :attachment_id
EOF,
['attachment_id' => $attachment_id],
);
}
public static function schemaDef(): array
{
return [