Eager load specific fields


Is it possible to eager load just some specific fields of the related model?

  async index ({ request, response, view }) {
    const structures = await Structure
    return structures

Let’s say i just want a single field from ‘reviews’, how could I do that?


Hey @iacapuca! :wave:

The method with() take a callback for the second argument.
You can modify the query inside it.

const structures = await Structure.query()
  .with('reviews', (builder) => {
    builder.select(['id', ...])


That worked just fine!

Does Adonis have something like a Laravel/Symphony Transformer? If so, how could I use it withing my controller?


You must explain what’s the job of the transformer and what exactly you are tying to do. Expecting others to search for transformers and then help you is not nice


I’m sorry, I dont mean that, I was just wondering if Adonis had Data Transformers like Laravel.


@iacapuca This could help :slight_smile:

It works perfect on few of my projects