CFWheels findAll Group By Having 子句

CFWheels findAll Group By Having Clause

在 CFWheels 中,我正在查看 findAll() 页面,它有一个 group by option by 没有 Having Clause 选项。有没有办法在 CFWheels.

中使用 findAll() 来使用 having 子句

非常失望的是,即使在新版本中也没有分组数据的动态过滤CFWheels 1.4.2

我找到的是 this issue, it is a very old issue posted under the cfwheels google group and a google group discussion. Even to this day the workaround for using a having in the group by statement is to use the cfrel by dumphreys,这是一个 ColdFusion 关系代数框架。

我建议尝试一下,它非常易于使用且编写清晰。如果您导航到 cfrel.cfc,您会发现一个 findAll() 函数,它看起来类似于 cfwheels 中的原始 findAll()查看 \wheels\model\read.cfm),但您会发现它开箱即用地支持 having()

示例(cfrel 有子句):

    /*  
    SQL: SELECT productId, SUM(total) AS totalSum FROM orders
         GROUP BY productId HAVING SUM(total) > ?
         ORDER BY totalSum DESC LIMIT 5
    PARAMS: [1000]
    */
    myOrdersRel = relation(datasource="cfrel")
        .select("productId,SUM(total) AS totalSum")
        .from("orders")
        .group("productId")
        .having("SUM(total) > ?", [1000])
        .order("totalSum DESC")
        .limit(5);
    query2 = rel2.query();

只是为了分享。感谢 Pankaj 在评论中的回答。谢谢

checklist = model("user_checklist").findAll(select="MAX(user_checklist.r_id)", group="r_id HAVING MAX(user_checklist.r_id) > 13");

给你

SELECT MAX(user_checklist.r_id) FROM user_checklist GROUP BY r_id HAVING MAX(user_checklist.r_id) > 13