package db import ( log "github.com/sirupsen/logrus" "reichard.io/imagini/internal/models" ) func (dbm *DBManager) CreateMediaItem (mediaItem models.MediaItem) (models.MediaItem, error) { log.Info("[db] Creating media item: ", mediaItem.RelPath) err := dbm.db.Create(&mediaItem).Error return mediaItem, err } func (dbm *DBManager) MediaItemsFromAlbum(user models.User, album models.Album) ([]models.MediaItem, error) { var mediaItems []models.MediaItem // db.Table("media_albums"). // Select("media_item.*"). // Joins("INNER JOIN media_items ON media_albums.ID = media_items.Albums"). // Where("media_albums.album_id = ? AND media_items.User = ?", albumID, userID). err := dbm.db. //Where("album = ? AND user = ?", albumID, userID). Find(&mediaItems).Error return mediaItems, err // db.Raw(` // SELECT // MediaItems.* // FROM // MediaAlbums // INNER JOIN MediaItems ON MediaAlbums.mediaID = MediaItems.mediaID // WHERE MediaAlbums.albumID = ? AND MediaItems.userID = ?`, albumID, userID) }