ORM: added generic getWhere which delegates appropriately based on model type.
This commit is contained in:
parent
0f21c48e66
commit
e148acd897
@ -100,6 +100,15 @@ public class ORM {
|
|||||||
return sql.rows(query, values)
|
return sql.rows(query, values)
|
||||||
.collect { recordToModel(modelClass, it) } }
|
.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) {
|
public def save(def model) {
|
||||||
if (model.id > 0) return update(model)
|
if (model.id > 0) return update(model)
|
||||||
else return create(model) }
|
else return create(model) }
|
||||||
@ -457,7 +466,7 @@ public class ORM {
|
|||||||
sqlParams << params.fileHash }
|
sqlParams << params.fileHash }
|
||||||
|
|
||||||
if (params.tags) {
|
if (params.tags) {
|
||||||
tags.eachWithIndex { tag, idx ->
|
params.tags.eachWithIndex { tag, idx ->
|
||||||
String L = "mft${idx}";
|
String L = "mft${idx}";
|
||||||
query.append(" JOIN media_files_tags $L ON ")
|
query.append(" JOIN media_files_tags $L ON ")
|
||||||
.append(" ${L}.media_file_id = mf.id AND ${L}.tag_id = ?")
|
.append(" ${L}.media_file_id = mf.id AND ${L}.tag_id = ?")
|
||||||
|
Loading…
Reference in New Issue
Block a user