2

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").)

  • 1
    If you want to filter by the value of the column of the joined table, why do you use `leftJoin` (instead of inner join) in the first place? – SergGr Oct 28 '17 at 11:08
  • 1
    Good question. I'm defining a generic base query that an API exposes for reuse. Some callers will not care about the left joined table or its values. Others will sometimes want to filter on it. – FullTimeCoderPartTimeSysAdmin Oct 28 '17 at 12:39

1 Answers1

2

Try mapping:

query.filter{ case (contact, maybePhone) => maybePhone.map(_.areaCode === "212") }
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66