代码之家  ›  专栏  ›  技术社区  ›  Bla...

Anorm多值支持不起作用

  •  0
  • Bla...  · 技术社区  · 9 年前

    Anorm的多值支持有一个奇怪的问题,当我使用 Seq 如中所述 documentation ..以下是我的疑问:

    控制器

    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 回复  |  直到 9 年前
        1
  •  2
  •   Bla...    9 年前

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

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