0

I have a method:

def nameToCode(nameStr){
    def ret = resortService.getResort("all")
    //this gets like 180 objects with various properties like name, code, etc.
    def resorts = [name: ret.prName, code: ret.prProductIndex]
    def code = resorts.findByName(nameStr) //this doesn't work
    println(code)
    return code
 }

I'm trying to call this method and send it a name. It's then supposed to go find the name in the map, if it finds it it's supposed to return the name's code. This is supposed to be simple but I've been searching everywhere and can't figure out how to do this. I'll appreciate any help. Thanks

1
  • Grails Dynamic Finders are available as static methods on Domain Classes, so if you wan't to use it you would probably need to do something like this: Resorts.findByName(nameStr). If you want to find something in map then you would need to use function find and pass closure to it. It's hard to tell what you want to do, can you explain it and post more code, for example you domain class Resorts? Commented Jun 9, 2016 at 8:46

1 Answer 1

2

you are using a gorm method on a standard map: Instead of :

 def resorts = [name: ret.prName, code: ret.prProductIndex]
    def code = resorts.findByName(nameStr) //this doesn't work

Try:

 def resorts = [name: ret.prName, code: ret.prProductIndex]
    def code = resorts.findAll{name==nameStr}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.