Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick - Filter Row if Column is Null

How do I filter rows in Slick if a column is null?

val employees = Queryable[Employees]

// Error
val query = employees.filter( _.terminationDate == Nil )

Might be important to note that

terminationDate: Option[String]

I am using Direct Embedding.

like image 314
BAR Avatar asked Feb 04 '15 16:02

BAR


1 Answers

Slick has its own why of checking for null values in a column:

val query = employees.filter(_.terminationDate.isNull)

The opposite is isNotNull.

Or in newer versions of Slick:

val query = employees.filter(_.terminationDate.isEmpty)

and

val query = employees.filter(_.terminationDate.isDefined)
like image 81
Ende Neu Avatar answered Sep 21 '22 14:09

Ende Neu