Rewrite MultiTableSelect queries with ON

Instead of `USING(EbookId)`, it would be easier to handle
`MultiTableSelect` queries in `FromMultiTableRow()` if the queries used

`ON Projects.EbookId = Ebooks.Ebooks`

This is because `USING` will return only one `EbookId` column, but `ON`
will return all columns from both tables.
This commit is contained in:
Mike Colagrosso 2024-12-31 21:24:58 -07:00 committed by Alex Cabal
parent dad5df0059
commit 0e7bff5d82
3 changed files with 13 additions and 12 deletions

View file

@ -660,21 +660,21 @@ final class Project{
* @return array<Project>
*/
public static function GetAllByStatus(Enums\ProjectStatusType $status): array{
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks using (EbookId) where Projects.Status = ? order by regexp_replace(Title, \'^(A|An|The)\\\s\', \'\') asc', [$status], Project::class);
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks on Projects.EbookId = Ebooks.EbookId where Projects.Status = ? order by regexp_replace(Title, \'^(A|An|The)\\\s\', \'\') asc', [$status], Project::class);
}
/**
* @return array<Project>
*/
public static function GetAllByManagerUserId(int $userId): array{
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks using (EbookId) where ManagerUserId = ? and Status in (?, ?) order by regexp_replace(Title, \'^(A|An|The)\\\s\', \'\') asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks on Projects.EbookId = Ebooks.EbookId where ManagerUserId = ? and Status in (?, ?) order by regexp_replace(Title, \'^(A|An|The)\\\s\', \'\') asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
}
/**
* @return array<Project>
*/
public static function GetAllByReviewerUserId(int $userId): array{
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks using (EbookId) where ReviewerUserId = ? and Status in (?, ?) order by regexp_replace(Title, \'^(A|An|The)\\\s\', \'\') asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
return Db::MultiTableSelect('SELECT * from Projects inner join Ebooks on Projects.EbookId = Ebooks.EbookId where ReviewerUserId = ? and Status in (?, ?) order by regexp_replace(Title, \'^(A|An|The)\\\s\', \'\') asc', [$userId, Enums\ProjectStatusType::InProgress, Enums\ProjectStatusType::Stalled], Project::class);
}
/**
@ -686,7 +686,6 @@ final class Project{
$object = Project::FromRow($row['Projects']);
if($row['Projects']->EbookId !== null){
$row['Ebooks']->EbookId = $object->EbookId;
$object->Ebook = Ebook::FromRow($row['Ebooks']);
}