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

hasAndBelongsToMany related array has only "null" entry when limiting fields #1076

Closed
technicallyfeasible opened this issue Feb 6, 2015 · 3 comments
Assignees
Labels

Comments

@technicallyfeasible
Copy link

I have a model which is related to another model (countries) through hasAndBelongsToMany. When I do a filter with include like this
{
"include": [{
"relation": "countries",
"scope": {
"fields": ["name"]
}
}]
}

then in my response I get something like this
"countries": [
null
]

and without the scope
"countries": [
{
"name": "Argentina",
"id": "54d11335123c16580c55e0c8",
"continentId": "54d11333123c16580c55e0c7"
}
]

@raymondfeng
Copy link
Member

Please create a test project on github to reproduce the issue per https://github.com/strongloop/loopback/wiki/Issues.

@technicallyfeasible
Copy link
Author

I created a test repository as described in the link:
https://github.com/technicallyfeasible/loopback-sandbox

Just start it and use the explorer __get__Companies with the following filter:
{"include":{"relation":"countries", "scope":{"fields":["name"]}}}

I expect the list of companies with the linked countries for each one but only the "name" property. Instead for each linked Country there is only "null" in the countries array.

@superkhau
Copy link
Contributor

The inclusion filter is erroneous applied to the association table. As a result, the queries on related tables all become null. @raymondfeng has a fix in the works at loopbackio/loopback-datasource-juggler#476. Track progress on that issue instead, closing this one.

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