Loopback-datasource-juggler: Filtering fields on second-level related models causes missing data

Created on 13 Aug 2015  路  6Comments  路  Source: loopbackio/loopback-datasource-juggler

When we use scope { fields: {} } to filter out the fields we want to use, this only works on certain levels in the structure.

In the example below we see that it works on the first level filter.

It also works as expected on the deepest-level relationships (person/membership/invoice).

It's does not work as expected on the subscription relation, when the following filter is added to the subscription relation we get no data in the memberships relation.

fields: {
  membershipId: true
}

Example filters:

{
  include: [{
    relation: 'person',
    scope: {
      fields: {
        memberId: true
      }
    }
  }, {
    relation: 'subscription',
    scope: {
      fields: {
        membershipId: true
      },
      order: 'date DESC',
      include: [{
        relation: 'membership',
        scope: {
          fields: {
            date: true
          },
          order: 'date DESC'
        }
      }]
    }
  }, {
    relation: 'invoice',
    scope: {
      fields: {
        lineItems: true
      }
    }
  }],
  fields: {
    id: true,
    personId: true,
    subscriptionId: true,
    invoiceId: true,
    date: true
  },
  order: 'created ASC'
}

/CC @mrfelton

bug stale

All 6 comments

Can you provide a link to a test project on Github? See https://github.com/strongloop/loopback/wiki/Issues#bug-report

Thanks for your reply @superkhau.

I have created a test project here: https://github.com/beeman/loopback-sandbox/tree/datasource-juggler-issue-693

Steps to reproduce:

  • clone project
  • npm install
  • node server/server.js

The project starts and creates some sample data.

To display the issue I have created 2 remote methods on a Test model: showFilterWorking and showFilterFailing.

I expect the output of showFilterFailing to have a subscription relationship, which it does, with under that a membership relationship, which it does not.

The difference between these two methods is very small: the filter in showFilterWorking does not have the fields object in the scope of subscription, whereas the showFilterFailing has this.

I hope that this explains this issue a bit better, if not please let me know what to explain in more detail.

Thanks @beeman good catch. Really appreciate your sample code. I reproduced it and label it as a bug.

So this bug still exists ?!

@anoop-ananthan yep, and I would not expect it to be fixed any time at all.

Issues are closed by the bot while the Loopback team builds IBM's priorities, not those from the community.

@beeman Thanks for letting me know. I'd have wasted a lot of time on this.

Was this page helpful?
0 / 5 - 0 ratings