Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala Slick 2在多个字段上连接?_Scala_Slick 2.0 - Fatal编程技术网

Scala Slick 2在多个字段上连接?

Scala Slick 2在多个字段上连接?,scala,slick-2.0,Scala,Slick 2.0,如何在多个字段上进行连接,如下面的示例所示 val ownerId = 1 val contactType = 1 ... val contact = for { (t, c) <- ContactTypes leftJoin Contacts on (_.id === _.typeId && _.ownerId === ownerId) if t.id === contactType } yield (c.?, t) 请注意x3上的“id”=x2。“type_i

如何在多个字段上进行连接,如下面的示例所示

val ownerId = 1
val contactType = 1
...
val contact = for {
  (t, c) <- ContactTypes leftJoin Contacts on (_.id === _.typeId && _.ownerId === ownerId)
  if t.id === contactType
} yield (c.?, t)

请注意x3上的“id”=x2。“type_id”和x2.owner_id=16

好的,所以在浏览网站和源代码之后,我想我终于找到了解决方案

leftJoin on()方法接受以下参数pred:(E1,E2)=>T,所以我们可以这样做

val contacts = for {
  (t, c) <- ContactTypes leftJoin Contacts on ( (type, contact) => {
    type.id === contact.typeId && contact.ownerId === ownerId
  } )
} yield (c.?, t)
val contacts=for{
(t,c){
type.id==contact.typeId&&contact.ownerId===ownerId
} )
}产量(c.?,t)

它根据需要生成sql查询。

右边的on子句是:{case(type,contact)=>type.id==contact.typeId&&contact.ownerId==ownerId}Vlad的内部大括号没有意义。@Epicurist为什么?你能解释一下吗?你不同意type.id===contact.typeId&&contact.ownerId===ownerId根本不需要大括号吗?@Epicurist大括号在这里是不需要的,但它们是有意义的
val contacts = for {
  (t, c) <- ContactTypes leftJoin Contacts on ( (type, contact) => {
    type.id === contact.typeId && contact.ownerId === ownerId
  } )
} yield (c.?, t)