Anorm多值支持不起作用

时间:2015-02-12 07:39:30

标签: scala playframework-2.2 anorm

我对Anorm的多值支持有这个奇怪的问题,当我使用documentation中写的Seq时,我的查询没有返回任何内容。这是我的查询:

控制器

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),则会按预期返回。知道为什么我的多值不起作用吗?

1 个答案:

答案 0 :(得分:2)

您可以通过从您的SBT项目中删除Play提供的依赖性常量anorm并添加完全限定/独立依赖项来将Anorm升级到具有此功能的2.3。

libraryDependencies ++= Seq( "com.typesafe.play" %% "anorm" % "2.3.7")
//2.3.7 is just an example, you can change it to any other version