groovy - Grails Gorm reference a property's (column's) value within a named query? -
So ... is there any way to do something like that?
class kitty {string name string nickname public static string getExpectedNickname (string name) {name.replaceAll return ('Mr.', '')} Fixed nameQueries = {{byKityWithPredictableNickname iLike 'name' , '% Kitty%' Ilike 'nickname', Kitty .getExpectedNickname ('name')}}}
Can I reference the value of the column value of the current row in some way ? I thought the property ('name') would work, but alas, no.
Edit:
Another example: I thought that something like this would work. ..but it does not :( ...
stable namedQueries = {{whyDoesntThisReturnEverything integer c = Kitty.bySubQuery (id) .count () // gives everything, when I " Instead 1 I get some stupid illegal logic exceptions:
.java.lang.ClassCastException @ 2af65a43 StackTrace is as follows: Message: java.lang.ClassCastException@2af65a43 line | method ->> | called | sun.reflect.GeneratedMethodAccessor327 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 43 | 606 | | sun.reflect.DelegatingMethodAccessorImpl invocation call ...... Java.lang.reflect.method | 1254 | In JlrMethodInvo Call | org.springsource.loaded.ri.ReflectiveInterceptor | 90 | Call | ... | Org.codehaus.groovy.reflection.CachedMethod | in | 57 | in groovy.lang.MetaBeanProperty GetProperty ...
I think the only way to do this is to do this < Code> sqlRestriction .
// ... in place of '%' like 'named' (name, 'mister') like stable namedQueries = {{findAllKitty iLike 'name', '% kitty%'} {findAllByNickNameLikeName sqlRestriction "NICK_NAME , '') || '%' "}} // to use: kitty.findalibainamenamename () List ()
SQL syntax will probably change depending on the database you are using.
Comments
Post a Comment