adonisjs / adonisjs/http-transformers

Transformer strange behavior

Open
#4 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
11
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Package version

2.3.1

Describe the bug

Controller:

return serialize(
  TagTransformer.paginate(tags.all(), tags.getMeta()).useVariant('toDashboardObject'),
)

When pick is used, here is the response:

export default class TagTransformer extends BaseTransformer<Tag> {
  toDashboardObject() {
    return this.pick(this.resource, ['id', 'slug', 'name', 'rated', 'archived'])
  }
}
{
    "data": [
        {
            "id": 1,
            "slug": "seinen",
            "name": "Seinen",
            "rated": "r_18",
            "archived": false
        },
        // Rest of the data
    ],
    "metadata": {
       // this part is OK
    }
}

When using omit:

export default class TagTransformer extends BaseTransformer<Tag> {
  toDashboardObject() {
    return this.omit(this.resource, ['description'])
  }
}
{
    "data": [
        {
            "modelOptions": {
                "connection": "mysql"
            },
            "fillInvoked": false,
            "cachedGetters": {},
            "forceUpdate": false,
            "$columns": [
                "archived",
                "createdAt",
                "description",
                "id",
                "name",
                "rated",
                "slug",
                "updatedAt"
            ],
            "$attributes": {
                "id": 1,
                "slug": "seinen",
                "name": "Seinen",
                "description": "",
                "rated": "r_18",
                "archived": false,
                "createdAt": "2026-04-08T16:07:22.000+02:00",
                "updatedAt": "2026-04-08T16:07:22.000+02:00"
            },
            "$original": {
                "id": 1,
                "slug": "seinen",
                "name": "Seinen",
                "description": "",
                "rated": "r_18",
                "archived": false,
                "createdAt": "2026-04-08T16:07:22.000+02:00",
                "updatedAt": "2026-04-08T16:07:22.000+02:00"
            },
            "$preloaded": {},
            "$extras": {},
            "$sideloaded": {},
            "$isPersisted": true,
            "$isDeleted": false,
            "$isLocal": false
        },
        // Rest of the data
    ],
    "metadata": {
       // this part is OK
    }
}
Reproduction repo

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the BaseTransformer implementations of pick and omit, then trace the TagTransformer useVariant('toDashboardObject') call from the controller. Compare how each method serializes the resource; the fix is done when omit returns the model's intended attributes without exposing internal model state while pagination metadata remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.