If you need only simple "startsWith" condition, you can use like:
Options.findAllByNameLike("abc%")
Frage
I have a domain-class called option
. There is an attribute called name
.
The names are like:
abc.1
abc.2
xxx.1
xxx.2
xxx.3
I want all options that start with abc. Normally I use Options.findByName("xyz") But i want all that start with abc. So in that example:
abc.1
abc.2
The regex could be /abc(.).*/
But where I have to write that?
Lösung
If you need only simple "startsWith" condition, you can use like:
Options.findAllByNameLike("abc%")
Andere Tipps
Consider using colusers inside the findAll /findByName method Have u tried this one ?
Example
def result = ["abc1", "acb2", "abc3"].findAll { it ==~ /abc.*/ }
or in your case
def result = Options.findByName { it ==~ /abc.*/ }
Or refer this link for bunch of reference on regular expression http://groovy.codehaus.org/Regular+Expressions
Cheers!