Remove primary key TocEntryId

Add a SortOrder column to order the TocEntries instead.
This commit is contained in:
Mike Colagrosso 2024-10-13 21:21:28 -06:00 committed by Alex Cabal
parent 2eb7fef027
commit c8e6524ef2
2 changed files with 6 additions and 6 deletions

View file

@ -1,7 +1,6 @@
CREATE TABLE `TocEntries` ( CREATE TABLE `TocEntries` (
`TocEntryId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`EbookId` int(10) unsigned NOT NULL, `EbookId` int(10) unsigned NOT NULL,
`TocEntry` text NOT NULL, `TocEntry` text NOT NULL,
PRIMARY KEY (`TocEntryId`), `SortOrder` tinyint(3) unsigned NOT NULL,
KEY `index1` (`EbookId`) KEY `index1` (`EbookId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View file

@ -279,7 +279,7 @@ class Ebook{
SELECT * SELECT *
from TocEntries from TocEntries
where EbookId = ? where EbookId = ?
order by TocEntryId order by SortOrder asc
', [$this->EbookId], stdClass::class); ', [$this->EbookId], stdClass::class);
foreach($result as $row){ foreach($result as $row){
@ -1827,12 +1827,13 @@ class Ebook{
private function AddTocEntries(): void{ private function AddTocEntries(): void{
if($this->TocEntries !== null){ if($this->TocEntries !== null){
foreach($this->TocEntries as $tocEntry){ foreach($this->TocEntries as $sortOrder => $tocEntry){
Db::Query(' Db::Query('
INSERT into TocEntries (EbookId, TocEntry) INSERT into TocEntries (EbookId, TocEntry, SortOrder)
values (?, values (?,
?,
?) ?)
', [$this->EbookId, $tocEntry]); ', [$this->EbookId, $tocEntry, $sortOrder]);
} }
} }
} }