gpt4 book ai didi

scala - 光滑的多个连接

转载 作者:行者123 更新时间:2023-12-03 12:09:00 29 4
gpt4 key购买 nike

对于两个表之间的联接完成

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

但是,如果需要在更多表之间进行联接,下面尝试的正确方法是什么,但是不起作用
   (for {
(computer, company,suppliers) <- Computers leftJoin Companies on (_.companyId === _.id)
//not right leftjoin Suppliers on (_.suppId === _.id)
if computer.name.toLowerCase like filter.toLowerCase()
}

最佳答案

第一个联接导致查询返回元组。元组组件之一具有要用于第二个联接的外键。您需要先在第二个连接条件中获取此组件,然后才能获取其字段。如果公司是表,则具有字段suppId,它将看起来像这样:

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

关于scala - 光滑的多个连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18537925/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com