How can I use a limit and a required in an include?
See original GitHub issueHi, I am trying to query an associated model via an include. I want to return only the models of the matched parents, returning only the first match of the children.
hook.params.sequelize = {
include: [
{
model: 'executions',
where: {
startedOn: null,
finishedOn: null,
},
limit: 1,
required: true,
}
]
}
Actual behavior
The result returns all the parents and it doesn’t matter if have executions or not.
"data": [
{
id: 'dcc0aedf-c0d6-4bbe-b34d-257b8e8e8263',
action: 9,
executions: [ [executions] ]
},
{
id: '31dadc19-1b8b-4b59-8ae6-ab9e28afcfb5',
action: 13,
executions: []
},
{
id: '442a8921-11fa-4e9c-ad8e-fe57ea6cc854',
action: 8,
executions: [ [executions] ]
},
]
Expected behavior
I want that the result returns only the parents that have executions.
"data": [
{
id: 'dcc0aedf-c0d6-4bbe-b34d-257b8e8e8263',
action: 9,
executions: [ [executions] ]
},
{
id: '442a8921-11fa-4e9c-ad8e-fe57ea6cc854',
action: 8,
executions: [ [executions] ]
},
]
System configuration
“feathers-sequelize”: “^6.2.0”
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top Results From Across the Web
how can i use limit in include model using sequelize
Show activity on this post. i want to get user's images at limit 2 from Follow model. so, i tried get user's images...
Read more >Limits intro (article) | Khan Academy
Limits describe how a function behaves near a point, instead of at that point. This simple yet powerful idea is the basis of...
Read more >What Is a Limit Order in Trading, and How Does It Work?
A limit order is used to buy or sell a security at a pre-determined price and will not execute unless the security's price...
Read more >Learn How to Use LIMIT Clause in SQL - Simplilearn
The LIMIT clause states that only maximum rows are included in the result collection (or exactly the maximum rows, in the event that...
Read more >LIMIT Clause - Apache Impala
This technique can be used to simulate "paged" results. Because Impala queries typically involve substantial amounts of I/O, use this technique only for ......
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 FreeTop 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
Top GitHub Comments
Thank you so much, that works with a little change. I had to add the property
duplicating: false
because before that I hadmissing FROM-clause entry for table "executions" at find execution-groups
error, so I searched and found a solution here https://github.com/feathersjs-ecosystem/feathers-sequelize/issues/248.For those ending up on this thread, duplicating false does solve the issue but messes up the limit and offset. For this to work you need to make separate queries (separate:true). This works for one-to-many relations but does not work with many-to-many as is indicated in this thread which is 7 years old and has still has not been solved https://github.com/sequelize/sequelize/pull/4525 and https://github.com/sequelize/sequelize/issues/8457