List with fetch parameter
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 fe开发者_如何学运维tch 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?
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' )
精彩评论