ORM: added generic getWhere which delegates appropriately based on model type.

This commit is contained in:
Jonathan Bernard 2016-03-14 03:50:11 -05:00
parent 0f21c48e66
commit e148acd897

View File

@ -100,6 +100,15 @@ public class ORM {
return sql.rows(query, values)
.collect { recordToModel(modelClass, it) } }
public def getWhere(Class modelClass, Map criteria) {
switch(modelClass) {
case Album: return getAlbumsWhere(criteria)
case Artist: return getArtistsWhere(criteria)
case Bookmark: return getBookmarksWhere(criteria)
case MediaFile: return getMediaFilesWhere(criteria)
case Playlist: return getPlaylistsWhere(criteria)
case Tag: return getTagsWhere(criteria) } }
public def save(def model) {
if (model.id > 0) return update(model)
else return create(model) }
@ -457,7 +466,7 @@ public class ORM {
sqlParams << params.fileHash }
if (params.tags) {
tags.eachWithIndex { tag, idx ->
params.tags.eachWithIndex { tag, idx ->
String L = "mft${idx}";
query.append(" JOIN media_files_tags $L ON ")
.append(" ${L}.media_file_id = mf.id AND ${L}.tag_id = ?")