Skip to content

modifyEager sometimes causes eager results not to be returned #309

@lucascolvin

Description

@lucascolvin

The simple eager query works well and includes all of the results. But when sometimes modifyEager causes an empty eager array to be returned;

Simple Example works well:

const users = await User.query()
    .eager('[roles, log_auth]')
[
    {
      "id": 1,
      "email": "[email protected]",
      "roles": [
        {
          "id": 2,
          "slug": "member-subscripted",
          "name": "Member with a paid subscription",
          "group": "MEMBER",
        }...
      ],
      "log_auth": [
        {
          "id": 1,
          "created_at": "2017-02-23T23:54:35.000Z",
          "user_id": 1
        }...
      ]
    }
  ]

Sometimes modifyEager works:

const users = await User.query()
    .eager('[roles, log_auth]')
    .modifyEager('roles', builder => {
      builder.select('roles.slug');
    })
[
    {
      "id": 1,
      "email": "[email protected]",
      "roles": [
        {
          "slug": "member-subscripted"
        }...
      ],
      "log_auth": [
        {
          "id": 1,
          "created_at": "2017-02-23T23:54:35.000Z",
          "user_id": 1
        }...
      ]
    }
  ]

But other times it doesn't:

const users = await User.query()
    .eager('[roles, log_auth]')
    .modifyEager('log_auth', builder => {
      builder.select('log_auth.created_at');
    })
[
    {
      "id": 1,
      "email": "[email protected]",
      "roles": [
        {
          "id": 2,
          "slug": "member-subscripted",
          "name": "Member with a paid subscription",
          "group": "MEMBER",
        }...
      ],
      "log_auth": []
    }
  ]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions