带有获取参数的列表

发布于 2024-12-04 11:11:58 字数 694 浏览 1 评论 0原文

我有一个名为 Address 的类,它有一个名为 clone 的布尔字段。我正在尝试使用 Grails list() 方法来显示 Address 类的实例,其中 clone = false。我虽然可以使用 fetch 参数来完成此操作,但它没有按预期工作。它不是只返回我想要的地址,而是返回 Address 类的所有实例。这就是我所拥有的:

def list = {
    params.max = Math.min(params.max ? params.int('max') : 10, 100)
    params.fetch = [clone:false]
    [addressInstanceList: Address.list(params), addressInstanceTotal: Address.count()]
}

即使我使它非常简单,获取仍然无法按预期工作。例如,如果我指定我只想获取邮政编码为“90210”的 Address 类的实例,我就写了这个,但它仍然为我提供了 Address 的所有实例> 类。

Address.list(fetch:[zip:"90210"])

我做错了什么?

I have a class called Address which has a boolean field called clone. I am trying to use the Grails list() method to show instance of the Address class where clone = false. I though I could use the fetch parameter to accomplish this, but it is not working as expected. Instead of returning only the addresses I want it returns all instances of the Address class. Here is what I have:

def list = {
    params.max = Math.min(params.max ? params.int('max') : 10, 100)
    params.fetch = [clone:false]
    [addressInstanceList: Address.list(params), addressInstanceTotal: Address.count()]
}

Even when I make it really simple fetch still does not work as expected. For example if I specify that I just want to fetch instances of the Address class with the zip code "90210" I wrote this, but it still gives me all instances of the Address class.

Address.list(fetch:[zip:"90210"])

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软的没边 2024-12-11 11:11:58

Domain.list() 方法的 fetch 参数不是用于过滤响应或仅获取某些项目,而是用于指定是否立即加载 Domain 类的属性或懒惰地

即(来自列表文档):

def results = Book.list(fetch:[authors:"eager"])

做你自己这样做,我相信您可以使用 findAllWhere 调用,例如:

Address.findAllWhere( clone:false, zip:'90210' )

The fetch parameter for the Domain.list() method is not for filtering the response or just fetching some items, it is for specifying whether properties of the Domain class are loaded eagerly or lazily

ie (from the documentation for list):

def results = Book.list(fetch:[authors:"eager"])

To do what you are doing, I believe you could use a findAllWhere call, such as:

Address.findAllWhere( clone:false, zip:'90210' )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文