Search code examples
grailsgrails-orm

Gorm finder with dynamic argument?


I am using a GORM finder but I am getting a runtime error and I think that is because my syntax is incorrect. Here is the line of code I have problems with:

def accountsOwnedByUser = AccountRecord.findAllWhere(owners.contains(indivRecord.uniqueId))

where owners is a List property of the AccountRecord class. I want to find all the owners of a given account and I'm doing it by searching for individuals whose unique id appears in the account's ownership list. But currently I get this error:

No such property: owners for class: com.twc.fatcaone.FileImportService. Stacktrace follows:
Message: No such property: owners for class: com.twc.fatcaone.FileImportService
    Line | Method
->>  968 | doCall                         in com.twc.fatcaone.FileImportService$_$tt__deleteIndividualRecord_closure18
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    967 | $tt__deleteIndividualRecord    in com.twc.fatcaone.FileImportService$$EOkgHOSW
|    168 | doCall . . . . . . . . . . . . in com.twc.fatcaone.FileImportService$_$tt__excelIndividualFileUpload_closure16$$EOkgHOSW
|    162 | $tt__excelIndividualFileUpload in com.twc.fatcaone.FileImportService$$EOkgHOSW
|    147 | upload . . . . . . . . . . . . in com.twc.fatcaone.CustomerController
|    198 | doFilter                       in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . . . . . . . . . . . in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker                      in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run                            in java.lang.Thread

I need something like it.owners or an equivalent thereof that can be used as an arguments to GORM's dynamic finder. Is there an equivalent?


Solution

  • Are you looking for something like this?...

    def idToSearchFor = indivRecord.uniqueId
    AccountRecord.where {
        idToSearchFor in owners    
    }.list()
    

    I can't tell for sure without seeing your model but something like that may help.