mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 23:00:28 -04:00
Remove primary key EbookSourceId
There is a one to many relationship between `Ebook` and `EbookSource`, and we don't query by `EbookSourceId`. We add a `SortOrder` column to keep the sources in the same order as specified in `content.opf`.
This commit is contained in:
parent
4e8ba5ddaa
commit
1076c9a77d
4 changed files with 19 additions and 9 deletions
|
@ -3,10 +3,10 @@
|
|||
use Safe\DateTimeImmutable;
|
||||
|
||||
class EbookSource{
|
||||
public ?int $EbookSourceId = null;
|
||||
public ?int $EbookId = null;
|
||||
public EbookSourceType $Type;
|
||||
public string $Url;
|
||||
public ?int $SortOrder = null;
|
||||
|
||||
public static function FromTypeAndUrl(EbookSourceType $type, string $url): EbookSource{
|
||||
$instance = new EbookSource();
|
||||
|
@ -39,6 +39,10 @@ class EbookSource{
|
|||
$error->Add(new Exceptions\EbookSourceUrlRequiredException());
|
||||
}
|
||||
|
||||
if(!isset($this->SortOrder)){
|
||||
$error->Add(new Exceptions\EbookSourceSortOrderRequiredException());
|
||||
}
|
||||
|
||||
if($error->HasExceptions){
|
||||
throw $error;
|
||||
}
|
||||
|
@ -50,12 +54,11 @@ class EbookSource{
|
|||
public function Create(): void{
|
||||
$this->Validate();
|
||||
Db::Query('
|
||||
INSERT into EbookSources (EbookId, Type, Url)
|
||||
INSERT into EbookSources (EbookId, Type, Url, SortOrder)
|
||||
values (?,
|
||||
?,
|
||||
?,
|
||||
?)
|
||||
', [$this->EbookId, $this->Type, $this->Url]);
|
||||
|
||||
$this->EbookSourceId = Db::GetLastInsertedId();
|
||||
', [$this->EbookId, $this->Type, $this->Url, $this->SortOrder]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue