Search code examples
scalaslickslick-3.0typesafe

Slick 3.2: Filtering on columns from left-joined table


Given the following using Slick 3.2:

val contacts = TableQuery[ContactTable]
val phones = TableQuery[PhoneTable]

val query = contacts.joinLeft(phones).on(_.contact_id === _.id)

query.filter{ case (contact, maybePhone) => ... }

maybePhone is a Rep[Option[PhoneTable]]. How can I filter on its properties? (Something like maybePhone.contains(_.areaCode === "212").)


Solution

  • Try mapping:

    query.filter{ case (contact, maybePhone) => maybePhone.map(_.areaCode === "212") }