Model Class Statistics Functions any model
Returns the number of rows that match the arguments (or all rows if no arguments are passed in).
Uses the SQL function
If no records can be found to perform the calculation on,
0 is returned.
|where||string||No||Maps to the
|include||string||No||Associations that should be included in the query using
|group||string||No||Maps to the
// Count how many authors there are in the table authorCount = model("author").count(); // Count how many authors that have a last name starting with an "A" authorOnACount = model("author").count(where="lastName LIKE 'A%'"); // Count how many authors that have written books starting with an "A" authorWithBooksOnACount = model("author").count(include="books", where="booktitle LIKE 'A%'"); // Count the number of comments on a specific post (a `hasMany` association from `post` to `comment` is required) // The `commentCount` method will call `model("comment").count(where="postId=#post.id#")` internally aPost = model("post").findByKey(params.postId); amount = aPost.commentCount();