getAll request on '_MANY' association
See original GitHub issueDescribe the bug I want to get ‘_MANY’ association and rest-hapi return all datas of the model of association
To Reproduce Steps to reproduce the behavior:
- Create ‘_MANY’ association
associations: {
companies: {
type: '_MANY',
alias: 'companies',
model: 'companies',
},
},
-
I am creating companies in the model companies
-
I post an id company in my companies association
-
I get the association companies and response contains all the companies whereas in the companies association i have only one company
{
"docs": [
{
"_id": "5d5cae2e3356752c4f2d4414",
"subsidiaries": [
{
"_id": "5d5cae373356752c4f2d4416",
"subsidiaries": [],
"name": "string",
"naf": "string",
"siret": "string",
"createdBy": "5d5c9e1a6b233e246ad4f611",
"createdAt": "2019-08-21T02:36:39.450Z",
"institutions": []
}
],
"name": "string",
"naf": "string",
"siret": "string",
"createdBy": "5d5c9e1a6b233e246ad4f611",
"createdAt": "2019-08-21T02:36:30.548Z",
"institutions": []
},
{
"_id": "5d5cae373356752c4f2d4416",
"subsidiaries": [],
"name": "string",
"naf": "string",
"siret": "string",
"createdBy": "5d5c9e1a6b233e246ad4f611",
"createdAt": "2019-08-21T02:36:39.450Z",
"institutions": []
},
{
"_id": "5d5ebd0207b9b804f763dc2a",
"subsidiaries": [],
"name": "Hey",
"naf": "string",
"siret": "string",
"createdBy": "5d5db71b1c99220acc90ae45",
"createdAt": "2019-08-22T16:04:18.189Z",
"institutions": []
}
],
"pages": {
"current": 1,
"prev": 0,
"hasPrev": false,
"next": 2,
"hasNext": false,
"total": null
},
"items": {
"begin": null,
"end": null,
"total": 3
}
}
Expected behavior getAll request on ‘_MANY’ association should return only the id’s of the association and not fulld datas of the corresponding model.
Desktop (please complete the following information):
- OS: OSX
- Browser: Chrome
- Version: 76.0.3809.100
Additional context Sorry for my deplorable English, i hope its comprehensive ! Thanks for your answer.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How to get all children or parents in a many ... - Stack Overflow
You need to set up the reverse association as well. Person.hasMany(Person, { as: 'Children', through: models.Person_Parent });.
Read more >Solved: HubSpot Community - Get all associations API
Solved: My immeidate challenge has to do with getting line items associated with a deal however according to this post ( which is...
Read more >Sequelize Many-to-Many Association example - Node.js ...
Way to implement Sequelize Associations example: many to many Relationship in Node.js - Sequelize Associate tutorial with example.
Read more >Advanced M:N Associations | Sequelize
By passing a string to through above, we are asking Sequelize to automatically generate a model named User_Profiles as the through table ...
Read more >MATCH - Cypher Manual - Neo4j
The MATCH clause allows you to specify the patterns Neo4j will search for in the database. This is the primary way of getting...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @Clemssss, it’s because you are overriding the
query
parameter in the middleware function instead of modifying it.getAll
internally uses thequery
parameter to filter the results based on the ownerId. When you override it, you erase the filter and therefore get all of thecompany
documents rather than the docs under theownerId
.Try changing your middleware to:
Not at all, its easy to miss!