Relationship Counts
Last updated
Was this helpful?
Was this helpful?
var post = getInstance( "Post" )
.withCount( [
"comments AS allCommentsCount",
{ "comments AS pendingCommentsCount": function( q ) {
q.where( "approved", 0 );
} },
{ "comments AS approvedCommentsCount": function( q ) {
q.where( "approved", 1 );
} }
] )
.findOrFail( 1 );
post.getAllCommentsCount();
post.getPendingCommentsCount();
post.getApprovedCommentsCount();