tags:

views:

465

answers:

1

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 =

*/

}

+2  A: 

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!

marzagao
Thanks! will try it out later today.
joe
joe, did it work?
trenton