How on AdonisJs I can paginate relations?


Hi everyone. How I can paginate relation model data on AdonisJs?
Is there any common way developers do?
I know that I can prepare response as

total: "20"
page: 1
category = await Category.query()
    .with('posts', builder => {'id', 'title', 'description', 'h1', 'text') // .paginate() // as example
      .where('slug', params.slug)

manually, but maybe there is some method, as on Laravel?

1 Like


Oh, I found solution! Here is an example:

category = await Category.findBy('slug', params.slug)
posts = await category.posts().paginate(1, 10)
1 Like


Yes, sometimes it helps to read the official documentation :slight_smile:



The documentation is a bit confusing as sometimes I go to 4.0 but using 4.1.