Kevin
Kevin

Reputation: 2291

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()]
}

Upvotes: 0

Views: 966

Answers (1)

Artur Nowak
Artur Nowak

Reputation: 5354

Try

RideInfo.getAllByGiveRide(true)

Upvotes: 2

Related Questions