Adonis js withCount multiple table data


#1

Hi, I am trying to return the total reply and total like for a comment like this

........ 
.with('onecomment', (builder) => builder.withCount('totalLike'))
.with('onecomment', (builder) => builder.withCount('totalReply'))

This above code only works for last one. It returns data for totalReply only in __meta__ . It works only for one. How can I return both the information? Thank you


#2

You can also use the query builder helper method getCount.

getCount(columnName = ‘*’)

const total = await Database
  .from('users')
  .getCount()                                   // returns number

Regarding your issue. I don’t know, but maybe with

.with('onecomment', (builder) => builder.withCount('totalLike', 'totalReply'))

#4

Thank you but this gives error .with('onecomment', (builder) => builder.withCount(['totalLike', 'totalReply'])) .


#5

This returns only the first one. For second one, it does nothing.


#6

And without an array like i posted above?


#7

Without array it returns the last one only.