带有获取参数的列表
我有一个名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Domain.list()
方法的fetch
参数不是用于过滤响应或仅获取某些项目,而是用于指定是否立即加载 Domain 类的属性或懒惰地即(来自列表文档):
做你自己这样做,我相信您可以使用
findAllWhere
调用,例如:The
fetch
parameter for theDomain.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 lazilyie (from the documentation for list):
To do what you are doing, I believe you could use a
findAllWhere
call, such as: