0

This compiles:

  val table1 = TableQuery[Table1]
  val table2 = TableQuery[Table2]

  val query = for {
    (t1, t2) <- table1 joinLeft table2 on (_.dsType === _.dsType)
  } yield (t1, t2)

This does not compile:

  val table1 = TableQuery[Table1]
  val table2 = TableQuery[Table2]

  val query = for {
    (t1, t2) <- table1 joinLeft table2 on (_.dsType === _.dsType && _.dsSk === _.dsSk)
  } yield (t1, t2)

What's the syntax to add two conditions to joinLeft ?

ps0604
  • 1,227
  • 23
  • 133
  • 330
  • 2
    Four underscores in your anonymous function indicate it should take four arguments, and each nth argument corresponds to the nth underscore. But `on` wants a function that takes 2 arguments. – Dylan Feb 05 '18 at 18:39

1 Answers1

3

You can specify to which table you ask for the attributes within the on and separate by the operator &&:

  val table1 = TableQuery[Table1]
  val table2 = TableQuery[Table2]

    val query = for {
      (t1, t2) <- table1.joinLeft(table2).on((tab1, tab2) => tab1.dsType === tab2.dsType && tab1.dsSk === tab2.dsSk)
    } yield (t1, t2)

Similar to this question was answered in: How to add AND to the join SLICK

Rodo
  • 312
  • 4
  • 12