How to count lines in Lift (Scala web framework)

I want to add a property to the User model that returns the number of rows in the Project table that have a user user id.

So something like this ...

def numProjects = {

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

     */

}
+5
source share
1 answer

According to the documentation here (found here), assuming you are looking for a project account for user id 1234 and believe that your Project model inherits the MetaMapper trait (possibly via KeyedMetaMapper), it seems that you can use the count method as such:

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

or

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

I can’t check, because I have not used Lift yet, but it looks right ... :) Let me know if it works!

+6
source

All Articles