Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit and skip parameters not working on relation model #4006

Closed
traghave opened this issue Sep 19, 2018 · 9 comments
Closed

limit and skip parameters not working on relation model #4006

traghave opened this issue Sep 19, 2018 · 9 comments
Assignees

Comments

@traghave
Copy link

traghave commented Sep 19, 2018

  1. I've created two Models Team and Resource
  2. Have created ManytoMany relation between these two models
  3. When i try to use get the related resource objects from Team, it always list me 25
    I tried to follow couple of links
    Querying associated model with scope and limit #1744
    but still no luck
    could you help?
    @jannyHou

Description/Steps to reproduce

  1. Create two models
  2. create manytomany relationship between these two models
  3. Query first by findById along with related model using include filter, result is always containing the 25 items from related model.
    tried with below filter object
    filter = {'include' : { 'relation' : 'resources', 'scope' : {'limit' : 2000, 'skip': 0}}};

Expected result

findById should return all the related model objects for the model.

Additional information

    "loopback-boot": "^2.6.5",
    "loopback-cascade-delete-mixin": "^1.0.1",
    "loopback-component-explorer": "^4.0.0",
    "loopback-component-passport": "^2.2.0",
    "loopback-connector-cloudant": "^1.2.4",
    "loopback-connector-mongodb": "^1.17.0",
    "loopback-context": "^1.0.0",
@traghave
Copy link
Author

@raymondfeng

@jannyHou
Copy link
Contributor

@traghave The cloudant connector somehow doesn't set the limit in the query. Working on a fix for it.

@jannyHou
Copy link
Contributor

@traghave What does "ManytoMany" in the description mean? Is it a HasManyThrough relation or something else? This is important for solving the issue.

@traghave
Copy link
Author

@jannyHou
we have this relation defined in json.

  "relations": {
    "resources": {
      "type": "hasAndBelongsToMany",
      "model": "Resource"
    }
  "relations": {
    "teams": {
      "type": "hasAndBelongsToMany",
      "model": "Team"
    }
  },

in Team and Resource models respectively.

@jannyHou
Copy link
Contributor

jannyHou commented Sep 21, 2018

Cloudant connector has the problem, haven't checked other connectors:

When many-to-many relation has a through model, for example

  • Team hasMany Resource through TeamResource
  • Resource hasMany Team through TeamResource

Query a team with its resources included using Team.findById(teamId, {include: {relation: 'resources', scope: {limit: 100}}})

The connector first finds all the through model instances using teamId, then do a recursive find for each of the teamResources using its resourceId, and the limit filter is applied on it, which causes the problem.

@jannyHou
Copy link
Contributor

jannyHou commented Sep 21, 2018

As a workaround fix, PR loopbackio/loopback-connector-cloudant#196 allows user to define a globalLimit to retrieve all the related model instances.

The real fix should:

  • compare with the other connectors see how they deal with include filter
  • investigate the possibility to find related model from through model in one query not a bunch of recursive queries, at least in the cloudant connector
  • if it's feasible to apply limit/skip/offset on the related model, create a PR for such a fix. If it's restricted by design, then document it and this workaround.

@dhmlau
Copy link
Member

dhmlau commented Sep 21, 2018

[email protected] has been released to contain the workaround PR loopbackio/loopback-connector-cloudant#196 .

@jannyHou
Copy link
Contributor

I am closing this issue.

User can set a globalLimit flag in the datasource settings to retrieve all the related models.

// in server/datasources.json file
cloudantDS: {
  name: '<name>',
  url: '<url>',
  database: '<databasename>',
  // `globalLimit` is the new configuration they need to addd
  globalLimit: 1000(or any number big enough for them)
}

@jannyHou
Copy link
Contributor

follow up issue see loopbackio/loopback-connector-cloudant#197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants