Support querying joined tables from main where clause
See original GitHub issueIs your feature request related to a problem? Please describe. It would be nice to be able to query joined tables from the main where clause rather than querying the joined tables themselves which may cause the joined tables information to be omitted from the result.
Describe the solution you’d like
Model.findAll({
include: [ Association1, Association2 ],
where: { [Op.or]: [
{ 'Association1.ModelId': id },
{ 'Association2.ModelId': id }
]}
})
Describe alternatives you’ve considered I’ve considered writing a raw query which is probably what I’ll have to do.
Usage example As I described above I ran into an issue where I needed to join a couple of associations to the model I’m querying but rather than querying each association via include (which may cause some of the associations to not load if certain conditions are or aren’t met) I need a way to query the model and associations.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:6 (4 by maintainers)
Top Results From Across the Web
SQL Joins Using WHERE or ON - Mode Analytics
This lesson of the SQL tutorial for data analysis covers the differences between filtering joined data using WHERE or ON. ON filters data...
Read more >How Do You Join SQL Tables?. WHERE or ON clause?
This article is an attempt to convince you to do the same if you are using WHERE clause. Instead, use ON clause to...
Read more >Specifying a Join in the WHERE Clause - IBM
You join two tables by creating a relationship in the WHERE clause between at least one column from one table and at least...
Read more >Join tables and queries - Microsoft Support
In a right outer join, the query includes all of the rows from the second table in the SQL statement FROM clause, and...
Read more >SQL JOIN TABLES: Working with Queries in SQL Server
The INNER JOIN query retrieves records from only those rows of both the tables in the JOIN query, where there is a match...
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
Note: I have started investigating this. Hopefully I will have time to complete it soon.
I’m not sure I understand this issue, isn’t this already available, but requires surrounding with
$
?