From a88c499b708bff64678314975fe1e3fc70d183cd Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Thu, 23 Apr 2020 19:22:41 +0200 Subject: [PATCH] Backend: Include categories when creating albums from labels Signed-off-by: Michael Mayer --- internal/query/selection.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/query/selection.go b/internal/query/selection.go index 9e7564737..1e57d119a 100644 --- a/internal/query/selection.go +++ b/internal/query/selection.go @@ -17,12 +17,14 @@ func (q *Query) PhotoSelection(f form.Selection) (results []entity.Photo, err er s = s.Table("photos"). Select("photos.*"). - Joins("LEFT JOIN photos_labels ON photos_labels.photo_id = photos.id"). - Joins("LEFT JOIN labels ON photos_labels.label_id = labels.id AND labels.deleted_at IS NULL"). + Joins("LEFT JOIN photos_labels pl ON pl.photo_id = photos.id"). + Joins("LEFT JOIN labels l ON pl.label_id = l.id AND l.deleted_at IS NULL"). + Joins("LEFT JOIN categories c ON c.label_id = pl.label_id"). + Joins("LEFT JOIN labels lc ON lc.id = c.category_id AND lc.deleted_at IS NULL"). Where("photos.deleted_at IS NULL"). Group("photos.id") - s = s.Where("photos.photo_uuid IN (?) OR labels.label_uuid IN (?)", f.Photos, f.Labels) + s = s.Where("photos.photo_uuid IN (?) OR l.label_uuid IN (?) OR lc.label_uuid IN (?)", f.Photos, f.Labels, f.Labels) if result := s.Scan(&results); result.Error != nil { return results, result.Error