groovy - Grails Gorm reference a property's (column's) value within a named query? -
groovy - Grails Gorm reference a property's (column's) value within a named query? -
so... there way this?
class kitty {     string name     string nickname     public static string getexpectednickname(string name) {          homecoming name.replaceall('mr. ', '')     }     static namedqueries = {         bykitywithpredictablenickname {             ilike 'name', '%kitty%'             ilike 'nickname', kitty.getexpectednickname('name')         }     } }    can reference value of current row's column value somehow? thought property('name') work, alas, no.
edit:
another example: thought work... doesn't :( ...
static namedqueries = {     whydoesntthisreturneverything {         int c = kitty.bysubquery(id).count() //returns when  set "1" instead of "id"         c == 1     }     bysubquery { long paramid ->         eq 'id', paramid     } }    instead stupid illegal argument exception:
java.lang.classcastexception@2af65a43. stacktrace follows: message: java.lang.classcastexception@2af65a43     line | method ->>   -1 | invoke                                in sun.reflect.generatedmethodaccessor327 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  |     43 | invoke                                in sun.reflect.delegatingmethodaccessorimpl |    606 | invoke . . . . . . . . . . . . . . .  in java.lang.reflect.method |   1254 | jlrmethodinvoke                       in org.springsource.loaded.ri.reflectiveinterceptor |     90 | invoke . . . . . . . . . . . . . . .  in org.codehaus.groovy.reflection.cachedmethod |     57 | getproperty                           in groovy.lang.metabeanproperty ...       
i think way through sqlrestriction.
//... static namedqueries = {     findallkitty {         ilike 'name', '%kitty%'     }      findallbynicknamelikename {         sqlrestriction "nick_name '%' || replace(name, 'mr. ', '') || '%' "     } }  //to use: kitty.findallbynicknamelikename().list()    the sql syntax alter depending on database using.
 grails groovy gorm named-query 
 
  
Comments
Post a Comment