【问题标题】:How to count rows in Lift (Scala's web framework)如何计算 Lift 中的行数(Scala 的 Web 框架)
【发布时间】:2010-09-12 05:40:33
【问题描述】:

我想向我的 User 模型添加一个属性,该属性返回 Project 表中具有用户的用户 ID 的行数。

所以像这样......

def numProjects = {

    /* somehow get count from Project table
       The straight sql would be:
       SELECT COUNT(*) FROM projects WHERE userId = <the current user>

     */

}

【问题讨论】:

    标签: scala lift


    【解决方案1】:

    根据文档 here(找到 here),假设您正在寻找 id 为 1234 的用户的项目计数并假设您的项目模型继承了 MetaMapper 特征(可能通过 KeyedMetaMapper),看起来你可以这样使用 count 方法:

    Project.count(By(User.id, 1234))
    

    Project.count(BySql("userId = ?", 1234))
    

    我无法测试,因为我还没有使用 Lift,但它看起来不错... :) 如果它有效,请告诉我!

    【讨论】:

      猜你喜欢
      • 2010-11-29
      • 2010-10-18
      • 2013-03-07
      • 2012-01-12
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      相关资源
      最近更新 更多