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

Include relation filter crashes loopback #3233

Closed
KevinMongiello opened this issue Feb 24, 2017 · 7 comments
Closed

Include relation filter crashes loopback #3233

KevinMongiello opened this issue Feb 24, 2017 · 7 comments
Assignees
Labels

Comments

@KevinMongiello
Copy link

Description/Steps to reproduce

Minimal repo with which to reproduce bug:
https://github.com/KevinMongiello/loopback_include_bug

Steps to reproduce:
0a) Run mongodb
0b) Open up explorer http://localhost:3333/explorer

  1. Create/Post a new author,
  2. Create/Post a new 'post'
  3. Open "GET" in author section
  4. Paste this in filter {"include": {"relation": "post", "scope": {"fields": "id"}} }
  5. hit enter / try it out
    Loopback will crash with TypeError: Cannot read property 'toString' of undefined

Expected result

Expected result is to return all authors with a property posts that only includes each post's id.
Actual result: Loopback crashes.

Additional information

darwin x64 6.2.0

[email protected] /Users/kmong/CaliberMind/Work/scrap/bugs/loopback_include_bug
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]

@deepakrkris deepakrkris self-assigned this Feb 27, 2017
@deepakrkris
Copy link

@KevinMongiello nice job with the sample repository! I am able to see the error. let me take a look at what is failing.

@deepakrkris
Copy link

@KevinMongiello This would need a fix, I have temporary solution for the issue, if you query with {"include": {"relation": "post", "scope": {"fields": ["id", "authorId"]}} } the error wouldnt occur

@deepakrkris
Copy link

deepakrkris commented Feb 27, 2017

@bajtos @superkhau the following line creates a filter with only the query fields {'post': {fields: 'id'}}, but does not add relation.keyFrom : authorId
https://github.com/strongloop/loopback-datasource-juggler/blob/76c73d55d28dfa150b9e004aeae12aafe0ce6475/lib/include.js#L311

so , the data retrieved does not have the authorId and later at line https://github.com/strongloop/loopback-datasource-juggler/blob/76c73d55d28dfa150b9e004aeae12aafe0ce6475/lib/include.js#L599 ,
we try to merge the relations {'post'} with the parent 'author' using authorId and it throws an error and crashes loopback

@superkhau
Copy link
Contributor

I'm not familiar enough with this area of code, @raymondfeng can you chime in here?

@ebarault
Copy link
Contributor

ebarault commented Feb 28, 2017

@bajtos @superkhau @raymondfeng @jannyHou : I reported this issue a while ago in the datasource-juggler:
Please see loopbackio/loopback-datasource-juggler#779 and loopbackio/loopback-datasource-juggler#890

For now you need to manually include the foreign key in the scope of the incriminated relation for it to work, otherwise it crashes the app

@KevinMongiello
Copy link
Author

I've found that {"include": {"relation": "post", "scope": {"fields": {"id": "true"} } } } works, and I am successfully using this as a solution right now. @deepakrkris @ebarault

@bajtos
Copy link
Member

bajtos commented Mar 1, 2017

Thank you @ebarault for chiming in. I am closing this issue as a duplicate of loopbackio/loopback-datasource-juggler#779 then.

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

No branches or pull requests

5 participants