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

loopback fails on referencesMany relation missing foreignKey in scope for nested hasMany inclusion #779

Open
ebarault opened this issue Nov 30, 2015 · 6 comments

Comments

@ebarault
Copy link
Contributor

  1. say model A as a referencesMany relation with model B
    and model B has a hasMany relation with model C
  2. adding a scope in relation A>B to restrict fields in a way that 'A.id' is not included in results
  3. doing a GET on model A to get B relations through referencesMany, using built-in methods, and including relation B>C using filter {include:C}

loopback fails with
TypeError: Cannot read property 'toString' of undefined at KVMap.keyToString (../api_loopback/node_modules/loopback-datasource-juggler/lib/include_utils.js:64:46) at Object.KVMap.mapImpl.set (../api_loopback/node_modules/loopback-datasource-juggler/lib/include_utils.js:70:13) at Object.buildOneToOneIdentityMapWithOrigKeys (../api_loopback/node_modules/loopback-datasource-juggler/lib/include_utils.js:19:11) at includeHasManySimple (../api_loopback/node_modules/loopback-datasource-juggler/lib/include.js:498:36) at processIncludeItem (../api_loopback/node_modules/loopback-datasource-juggler/lib/include.js:275:16) at ../api_loopback/node_modules/loopback-datasource-juggler/lib/include.js:173:5 at ../api_loopback/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:157:13 at _each (../api_loopback/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:57:9) at Object.async.each (../api_loopback/node_modules/loopback-datasource-juggler/node_modules/async/lib/async.js:156:9) at Function.Inclusion.include (../api_loopback/node_modules/loopback-datasource-juggler/lib/include.js:172:9)

Obviously the include cannot work as i'm missing the id for relation hasMany to work, but this should be caught silently and not return the inclusion (which is actually the intent) rather than killing the server

Could easily fix this, but as there are many places to do so, i'd prefer to wait for proper guidance before submitting a fix proposal.

Eric

@jannyHou jannyHou self-assigned this Jun 3, 2016
@jannyHou jannyHou added bug and removed triaging labels Jun 3, 2016
@jannyHou
Copy link
Contributor

jannyHou commented Jun 3, 2016

adding a scope in relation A>B to restrict fields in a way that 'A.id' is not included in results

I think you mean B.id is not included here right?

But anyway I reproduced it and I think a proper way to handle it is throwing an error in response body.
Thought?

@jannyHou
Copy link
Contributor

Same error reported here: #890

@ebarault
Copy link
Contributor Author

ebarault commented Mar 1, 2017

For the track record, same error reported here: strongloop/loopback#3233

@deepakrkris deepakrkris changed the title loopback fails on referencesMany relation missing foreignKey in scope for nested hasMany inclusion loopback fails on referencesMany relation missing foreignKey in scope for nested hasMany inclusion Mar 16, 2017
@luxigo
Copy link

luxigo commented Oct 10, 2017

👍 easy way to crash server

@bostjanpisler
Copy link
Contributor

bostjanpisler commented Mar 20, 2022

For anyone having this issue with a mounted lb3 app inside an lb4 app, this error can happen for a model that has scope.include defined in the model definition json file.

Can probably also happen standalone.

@bostjanpisler
Copy link
Contributor

@raymondfeng si there at least a way to catch the error so that the server doesn't crash until a fix is made?

Optimally the field would be included automatically, can be a flag on the model if it needs to be opt-in.

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

8 participants