Question

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

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>

     */

}
Was it helpful?

Solution

According to the documentation here (found here), assuming you're looking for the project count for a User of id 1234 and assuming that your Project model inherits the MetaMapper trait (probably through KeyedMetaMapper), it seems you can use the count method as such:

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

or

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

I can't test because I haven't used Lift yet, but it looks right... :) Let me know if it works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top