How can I make a query with a like
when the object is a column[Option[String]]
?
This is my model:
val id: Rep[Int] = column[Int]("id", O.AutoInc, O.PrimaryKey)
val ownerName: Rep[String] = column[String]("owner_name")
val membershipCode: Rep[Option[String]] = column[Option[String]]("membership_code")
And this is my query:
val query = orderTableQuery.filter { order =>
Seq(
search.filter(!_.isEmpty).map(filterString => {
val searchTerm = s"%$filterString%".toLowerCase
Seq(
// Some(order.membershipCode.toLowerCase like searchTerm), // This is the one causing problems
Some(order.ownerName.toLowerCase like searchTerm) // This works fine
).flatten.reduceLeftOption(_ || _).getOrElse(true: Rep[Boolean])
}),
// ...other optional filters
).flatten.reduceLeftOption(_ && _).getOrElse(true: Rep[Boolean])
}
However, when I try to remove the comment tags from that line, the type of the sequence changes, so i can not make the reduceLeftOption(_ || _)
part, if I add a get
inside the option column then it compile fine, but when i try the query slick throws an error because you can not use a get in the database (which for me makes sense), but then, how can I handle this Option[String]
column?
I have already post this question in SO with no luck, any guide will be appreciated.
I have tried some things, like:
Compile fine, but in execution throws exception in the get
Some(order.membershipCode.get.toLowerCase.like(searchTerm))
The reduceLeftOption(_ || _)
does not work anymore
Some(order.membershipCode.toLowerCase.like(searchTerm))
Type mismatch
Some(order.membershipCode.toLowerCase.like(Some(searchTerm)))
--
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/ed9a1f68-fb64-4508-bbc9-b1c5ca0bf86e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.