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> */ }
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:
or
I can’t test because I haven’t used Lift yet, but it looks right… 🙂 Let me know if it works!