"exclude" instead of "include" / find where not exists
See original GitHub issueThe following:
User.findAndCountAll({
include: [
{ model: Profile, required: true}
]
});
Will return users that have a profile.
How do I return users that have no profile? Is there an exclude
?
Also, can I perform additional where
statements on the relation? E.g. I want to return all users that have no profile with an avatar. Something like this?
User.findAndCountAll({
include: [
{ model: Profile, required: true, where: {avatar: null}}
]
});
Issue Analytics
- State:
- Created 8 years ago
- Reactions:18
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Not exists - Exclude records those are having status in 0 ...
I want to get only B, C, D as output from the query. Lets say, 0 is status-complete & I want to ignore...
Read more >Consider using [NOT] EXISTS instead of [NOT] IN with a ...
Phil Factor explains why you should prefer use of [NOT] EXISTS over [NOT] IN, when comparing data sets using a subquery.
Read more >How to filter entities not contained from an existing list with ...
The WhereBulkNotContains method lets you filter a LINQ query by excluding all items from an existing list. Example. var customers = context.Customers.
Read more >SQL Query to Exclude Records if it Matches an Entry in ...
NOT IN operators acts as a negation of In operator and return the results excluding the items present in the specified list. Syntax:...
Read more >Syntax and Examples of SQL EXCLUDE - eduCBA
columns or field names that have to be fetched for the final result set. ... Find details of all the students excluding students...
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
I believe that this will fail with the following error if you include a “limit” clause.
This can be achieved by adding
userId IS NULL
to the outer where clause. For it to be fully supported in sequelize you’ll need to wait for https://github.com/sequelize/sequelize/issues/3095, but in the meantime you can do