我使用Slick 1.0.0-RC1。我有這樣的定義表對象:爲什麼在調用take()方法時生成子查詢
object ProductTable extends Table[(Int, String, String, String, Double, java.sql.Date, Int, Option[Int], Int, Boolean)]("products") {
def id = column[Int]("productId", O.PrimaryKey, O.AutoInc)
def title = column[String]("title")
def description = column[String]("description")
def shortDescription = column[String]("shortDescription")
def price = column[Double]("price")
def addedDate = column[java.sql.Date]("addedDate")
def brandId = column[Int]("brandId")
def defaultImageId = column[Option[Int]]("defaultImageId")
def visitCounter = column[Int]("visitCounter")
def archived = column[Boolean]("archived")
def * = id ~ title ~ description ~ shortDescription ~ price ~ addedDate ~ brandId ~ defaultImageId ~ visitCounter ~ archived
}
我需要一個簡單的查詢,其選擇從數據庫8行:
ProductTable.filter(_.title === "something")
.sortBy(_.visitCounter)
.map(_.title)
.take(8)
.selectStatement
,輸出是:
select x2.x3 from
(select x4.`title` as x3 from `products` x4
where x4.`title` = 'something'
order by x4.`visitCounter` limit 8) x2
如果我擺脫take()
方法:
ProductTable.filter(_.title === "something")
.sortBy(_.visitCounter)
.map(_.title)
.selectStatement
則輸出是:
select x2.`title` from `products` x2
where x2.`title` = 'something'
order by x2.`visitCounter`
所以我的問題是:當其查詢對象與take()
方法構造爲什麼油滑生成一個子查詢?
P.S.如果它可以相關,我使用MySql驅動程序與所有這些
翻蓋周圍的地圖,並採取 – virtualeyes
你有試過嗎?它不會改變輸出SQL – wassertim
發佈到Slick用戶組,Zeiger會比任何人都更瞭解爲什麼會生成一個子選擇.... – virtualeyes