【问题标题】:Gorm finder with dynamic argument?具有动态参数的 Gorm finder?
【发布时间】:2014-07-21 20:13:16
【问题描述】:

我正在使用 GORM finder,但出现运行时错误,我认为这是因为我的语法不正确。这是我遇到问题的代码行:

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

其中 owner 是 AccountRecord 类的 List 属性。我想找到给定帐户的所有所有者,我通过搜索其唯一 ID 出现在帐户所有权列表中的个人来做到这一点。但目前我收到此错误:

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

我需要像it.owners 或类似的东西,可以用作GORM 动态查找器的参数。有没有等价物?

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    你在寻找这样的东西吗?...

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

    如果没有看到你的模型,我无法确定,但类似的东西可能会有所帮助。

    【讨论】:

    • 这会给我一个 AccountRecord 对象的列表,以便它们的所有者(List)属性包含 indivRecord 的唯一 ID?如果是这样,我认为这正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2019-11-06
    • 2011-09-05
    • 2017-09-28
    • 1970-01-01
    • 2016-03-13
    相关资源
    最近更新 更多