Adonis js withCount multiple table data


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


You can also use the query builder helper method getCount.

getCount(columnName = ‘*’)

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

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

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


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


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


And without an array like i posted above?


Without array it returns the last one only.