'OR' some QueryParam(s) Lift mapper

186 views Asked by At

Is there any way to "OR" two or more QueryParam s in liftWeb (scala) ? For example, the following code snippet , creates two QueryParams, but 'User.findAll' create "AND" clause, I mean that it finds every user that satisfies both 'queryParam1' and 'queryParam2'.

val queryParam1 = By(User.firstName , "guest")
val queryParam2 = By(User.lastName , "guest)
User.findAll(queryParam1 , queryParam2)

But I want to find users that satisfy 'queryParam1' OR 'queryParam2', and the only way that I've found so far, is to create a plain SQL query myself.

Is there any way other than creating a SQL query ?

Thanks a lot :)

1

There are 1 answers

0
Allen Chou On

Happen to see this question, bet you have got it nailed and as our company also use Lift but with Lift-Record(another persistence layer besides Mapper), so write our implementation down.

With the support with Lift-Json, we can write query like this.

 findAll(("$or" -> ("firstName" , "guest") ~ ("lastName", "guest")))

BTW, $or originally supported by MongoDB(one of its modifiers). So I guess Lift-Mapper may have provide similar support.