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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With