Pagination with pivot table?


#1

I have this query:

async show ({ request, params: { id }, view }) {
  const page = request.input('page', 1)

  const group = await Group.query()
    .where({ id })
    .with('users', (builder) => {
      builder.select('id', 'username').paginate(page, 50)
    })
    .first()

  if (! group) throw new HttpException('Page not found.', 404)
  return view.render('pages.groups.show', { group: group.toJSON() })
}

But I am getting this error:

ER_NONUNIQ_TABLE: Not unique table/alias: 'pivot_group_user'

How can I solve that?
Thank you in advance.


#2

@lffg : Can you share the details about the table mapping you created?

The error that you see is nothing in specific to adonisjs / lucid. but you have to check the underlying knex API for the details.

refer this to understand your issue & a suggested solution -https://github.com/bookshelf/bookshelf/issues/466