mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 19:06:49 -04:00
Remove primary key EbookTagId
Add a SortOrder column so that tags are presented in the same order as listed in content.opf.
This commit is contained in:
parent
b4b6fde778
commit
4e8ba5ddaa
2 changed files with 6 additions and 6 deletions
|
@ -1,7 +1,6 @@
|
||||||
CREATE TABLE `EbookTags` (
|
CREATE TABLE `EbookTags` (
|
||||||
`EbookTagId` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
||||||
`EbookId` int(10) unsigned NOT NULL,
|
`EbookId` int(10) unsigned NOT NULL,
|
||||||
`TagId` int(10) unsigned NOT NULL,
|
`TagId` int(10) unsigned NOT NULL,
|
||||||
PRIMARY KEY (`EbookTagId`),
|
`SortOrder` tinyint(3) unsigned NOT NULL,
|
||||||
UNIQUE KEY `idxUnique` (`EbookId`,`TagId`)
|
UNIQUE KEY `idxUnique` (`EbookId`,`TagId`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
|
@ -144,7 +144,7 @@ class Ebook{
|
||||||
from Tags t
|
from Tags t
|
||||||
inner join EbookTags et using (TagId)
|
inner join EbookTags et using (TagId)
|
||||||
where EbookId = ?
|
where EbookId = ?
|
||||||
order by et.EbookTagId
|
order by SortOrder asc
|
||||||
', [$this->EbookId], EbookTag::class);
|
', [$this->EbookId], EbookTag::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1691,13 +1691,14 @@ class Ebook{
|
||||||
}
|
}
|
||||||
|
|
||||||
private function AddTags(): void{
|
private function AddTags(): void{
|
||||||
foreach($this->Tags as $tag){
|
foreach($this->Tags as $sortOrder => $tag){
|
||||||
try{
|
try{
|
||||||
Db::Query('
|
Db::Query('
|
||||||
INSERT into EbookTags (EbookId, TagId)
|
INSERT into EbookTags (EbookId, TagId, SortOrder)
|
||||||
values (?,
|
values (?,
|
||||||
|
?,
|
||||||
?)
|
?)
|
||||||
', [$this->EbookId, $tag->TagId]);
|
', [$this->EbookId, $tag->TagId, $sortOrder]);
|
||||||
}
|
}
|
||||||
catch(Exceptions\DuplicateDatabaseKeyException){
|
catch(Exceptions\DuplicateDatabaseKeyException){
|
||||||
// The Ebook already has the Tag, which is fine.
|
// The Ebook already has the Tag, which is fine.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue