在Slick中为joinLeft添加两个条件

时间:2018-02-05 17:29:42

标签: scala slick slick-3.0

编译:

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

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

编译:

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

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

joinLeft添加两个条件的语法是什么?

1 个答案:

答案 0 :(得分:3)

您可以指定您在哪个表格中询问属性,并由运营商&amp;&amp;分隔:

  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)

与此问题类似,答案如下: How to add AND to the join SLICK