Blankman
Blankman

Reputation: 267320

How to add an and clause when using inSetBind

Trying to add a '&&' clause to my filter when using inSetBind but I can't.

This works:

db.run(lists.filter(f => f.id inSetBind(listIds)).result)

When I try to add a && clause I get an error:

db.run(lists.filter(f => f.id inSetBind(listIds) && (f.locationId === locationId)).result)

Error is:

ambiguous implicit values:
[error]  both value BooleanOptionColumnCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[slick.lifted.Rep[Option[Boolean]]]
[error]  and value BooleanCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[Boolean]
[error]  match expected type slick.lifted.CanBeQueryCondition[Nothing]

Upvotes: 0

Views: 133

Answers (1)

Silvio Mayolo
Silvio Mayolo

Reputation: 70397

From what I can tell, it's a simple parse error. Scala sees

lists.filter(f => f.id inSetBind(listIds) && (f.locationId === locationId))

and parses it as

lists.filter(f => f.id (inSetBind(listIds) && (f.locationId === locationId)))

so it's understandably confused. Try

lists.filter(f => (f.id inSetBind(listIds)) && (f.locationId === locationId))

Or, probably more clear in this case

lists.filter(f => f.id.inSetBind(listIds) && (f.locationId === locationId))

Scala's precedence rules can be found here. Infix operators that begin with a letter (such as inSetBind) have lower precedence than any other (infix) operator, which is why && binds more tightly than it.

Upvotes: 1

Related Questions