question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support querying joined tables from main where clause

See original GitHub issue

Is 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:open
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
papbcommented, Aug 5, 2019

Note: I have started investigating this. Hopefully I will have time to complete it soon.

0reactions
ephyscommented, Oct 6, 2022

I’m not sure I understand this issue, isn’t this already available, but requires surrounding with $ ?

Model.findAll({
  include: [ Association1, Association2 ],
  where: { [Op.or]: [
    { '$Association1.ModelId$': id },
    { '$Association2.ModelId$': id }
  ]}
})
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found