diff --git a/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy b/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy index ae74c06..abfe523 100644 --- a/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy +++ b/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy @@ -167,7 +167,7 @@ public class DbApi { def query = new StringBuilder() .append('DELETE FROM ') .append(pluralize(nameFromModel(model.class.simpleName))) - .append('WHERE id = ?') + .append(' WHERE id = ?') .toString() logger.debug('Deleting model.\n\tSQL: {}\n\tPARAMS: {}', @@ -556,10 +556,12 @@ public class DbApi { if (params.albumId || params.artistId || params.mediaFileId) { query.append(' JOIN playlists_media_files pmf ON ') - .append(' pmf.media_file_id = mf.id ') } + .append(' pmf.playlist_id = p.id ') + .append(' JOIN media_files mf ON ') + .append(' pmf.media_file_id = mf.id ') } if (params.mediaFileId) { - query.append(' AND mf.media_file_id = ? ') + query.append(' AND mf.id = ? ') sqlParams << params.mediaFileId } if (params.albumId) {