我有ANORM的多值支持這個奇怪的問題,當我使用Seq
寫在documentation我的查詢不返回任何東西。這裏是我的查詢:ANORM多值支持不起作用
控制器
def checkStock(data: Recap): Boolean = DB.withConnection { implicit conn =>
var so_id_list: Set[String] = Set()
for(ls <- data.recap_items){
for(rs <- ls.invoice_items){
so_id_list = so_id_list ++ Set(rs.id.toString)
}
}
breakable{
play.api.Logger.info(so_id_list.toSeq.toString)
//return ArrayBuffer(4, 5)
val result = Sales_Order.getSO_detailbyIDlist(so_id_list.toSeq)
play.api.Logger.info(result.toString)
//return List()
}
}
模型
def getSO_detailbyIDlist(so_id_list: Seq[String]):List[SO_detail] = DB.withConnection{ implicit c =>
SQL("""SELECT detailso.sur_key, detailso.so_id AS so_id, detailso.product_id, detailso.qty, product.name, detailso.unit_name, detailso.unit_multiplier, detailso.price, detailso.discount, detailso.contract, COALESCE(rs.left_qty, 0) AS left_qty
FROM detailso
LEFT JOIN product ON detailso.product_id = product.id
LEFT JOIN (SELECT Product.id, COALESCE(SUM(StockCard.left_qty), 0) as left_qty
FROM Warehouse_Product
LEFT JOIN Product ON Product.id = Warehouse_Product.product_id
LEFT JOIN Warehouse ON Warehouse.id = Warehouse_Product.warehouse_id
LEFT JOIN StockCard ON Stockcard.warehouse_product_id = Warehouse_Product.id
WHERE Warehouse.id = '110' AND StockCard.status = 1
GROUP BY id) rs ON rs.id = product.id
WHERE detailso.so_id IN ({so_id_list})
GROUP BY detailso.sur_key""").on('so_id_list -> so_id_list).as(SO_detailParser *)
}
如果我將IN
查詢更改爲手冊IN (4,5)
,則它會按預期返回。任何想法爲什麼我的多值不起作用?
您需要精確的Anorm版本:多值在2.3發佈。 – cchantep 2015-02-12 08:01:19
你是對的,我用Play 2.2 ..謝謝..你知道任何解決方法來實現相同的事情嗎? – 2015-02-12 08:24:34
Anorm可作爲獨立依賴項提供。沒有什麼可以阻止使用2.3(甚至是play2.2)。 – cchantep 2015-02-12 08:41:43