Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For Rails4:</p> <p>So, what you're wanting is an inner join, so you really should just use the joins predicate:</p> <pre><code> Foo.joins(:bar) Select * from Foo Inner Join Bars ... </code></pre> <p>But, for the record, if you want a "NOT NULL" condition simply use the not predicate:</p> <pre><code>Foo.includes(:bar).where.not(bars: {id: nil}) Select * from Foo Left Outer Join Bars on .. WHERE bars.id IS NOT NULL </code></pre> <p>Note that this syntax reports a deprecation (it talks about a string SQL snippet, but I guess the hash condition is changed to string in the parser?), so be sure to add the references to the end:</p> <pre><code>Foo.includes(:bar).where.not(bars: {id: nil}).references(:bar) </code></pre> <blockquote> <p>DEPRECATION WARNING: It looks like you are eager loading table(s) (one of: ....) that are referenced in a string SQL snippet. For example:</p> <pre><code>Post.includes(:comments).where("comments.title = 'foo'") </code></pre> <p>Currently, Active Record recognizes the table in the string, and knows to JOIN the comments table to the query, rather than loading comments in a separate query. However, doing this without writing a full-blown SQL parser is inherently flawed. Since we don't want to write an SQL parser, we are removing this functionality. From now on, you must explicitly tell Active Record when you are referencing a table from a string:</p> <pre><code>Post.includes(:comments).where("comments.title = 'foo'").references(:comments) </code></pre> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload