【发布时间】:2013-02-01 22:19:48
【问题描述】:
我正在尝试使用 SLICK 1.0.0 生成此 SQL:
select
cat.categoryId,
cat.title,
(
select
count(product.productId)
from
products product
right join products_categories productCategory on productCategory.productId = product.productId
right join categories c on c.categoryId = productCategory.categoryId
where
c.leftValue >= cat.leftValue and
c.rightValue <= cat.rightValue
) as productCount
from
categories cat
where
cat.parentCategoryId = 2;
我最成功的尝试是(我去掉了“joins”部分,所以它更具可读性):
def subQuery(c: CategoriesTable.type) = (for {
p <- ProductsTable
} yield(p.id.count))
for {
c <- CategoriesTable
if (c.parentId === 2)
} yield(c.id, c.title, (subQuery(c).asColumn))
在子查询中产生缺少括号的 SQL:
select
x2.categoryId,
x2.title,
select count(x3.productId) from products x3
from
categories x2
where x2.parentCategoryId = 2
这显然是无效的SQL 任何想法如何让 SLICK 将这些括号放在正确的位置?或者也许有不同的方法来实现这一点?
【问题讨论】:
-
你能在你的尝试旁边发帖吗?
-
我发布了我目前所拥有的
-
对我来说,这看起来像是查询编译器中的错误/疏忽。也许你应该提交一份错误报告。
-
好的。我已经做到了:github.com/slick/slick/issues/104
标签: scala scalaquery slick