Search code examples
grailsgrails-domain-classgrails-controller

How to get data with condition in Grails controller?


In my RideInfo domain class there is a field named giveRide. In the controller, I would like to get all data from table RideInfo whose giveRide equlas to TRUE, how can it do that? Thanks.

This piece of code doesn't work:

def listDriver = {
    params.max = Math.min(params.max ? params.int('max') : 10, 100)
    rideInfoInstance = RideInfo.get(giveRide=true)
    [rideInfoInstanceList: rideInfoInstance, rideInfoInstanceTotal: rideInfoInstance.count()]
}

Neither:

def listDriver = {
    params.max = Math.min(params.max ? params.int('max') : 10, 100)
    params.giveRide=true
    [rideInfoInstanceList: RideInfo.list(params), rideInfoInstanceTotal: RideInfo.count()]
}

Solution

  • Try

    RideInfo.getAllByGiveRide(true)