多个连接光滑 [英] multiple joins with slick

查看:35
本文介绍了多个连接光滑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个表之间的连接是这样完成的

For joining between two tables is done like

    (for {
    (computer, company) <- Computers leftJoin Companies on (_.companyId === _.id)
    if computer.name.toLowerCase like filter.toLowerCase()
    }

但是,如果需要在更多表之间进行连接,下面尝试的正确方法是什么,但不起作用

But in case if joining required between more tables what is the right way trying below but doesnt work

   (for {
    (computer, company,suppliers) <- Computers leftJoin Companies on (_.companyId ===        _.id)
     //not right leftjoin Suppliers on (_.suppId === _.id)
    if computer.name.toLowerCase like filter.toLowerCase()
  }

推荐答案

第一次联接导致查询返回元组.元组组件之一具有要用于第二个连接的外键.在获取其字段之前,您需要在第二个连接条件中获取此组件.如果 Companies 是表,则该表具有 suppId 字段,它看起来像这样:

The first join results in a Query returning Tuples. One of the tuple components has the foreign key you want to use for the second join. You need to get this component in the second join condition before getting its field. If Companies is the table, that has the field suppId it would look like this:

(for {
  ((computer, company),suppliers) <- Computers leftJoin Companies on (_.companyId === _.id) leftJoin Suppliers on (_._2.suppId === _.id)
  if computer.name.toLowerCase like filter.toLowerCase()
} yield ... )

这篇关于多个连接光滑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆