You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're using Rails 6.1 or higher, prefer `where.missing`
over `left_joins` and `where` to find missing relationship records.
It can be expressed in a more simplified.
```ruby
# bad
Post.left_joins(:author).where(authors: { id: nil })
# good
Post.where.missing(:author)
```
Copy file name to clipboardExpand all lines: README.adoc
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -938,6 +938,19 @@ User.where("id != ?", id)
938
938
User.where.not(id: id)
939
939
----
940
940
941
+
=== Finding missing relationship records [[finding-missing-relationship-records]]
942
+
943
+
If you're using Rails 6.1 or higher, use https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods/WhereChain.html#method-i-missing[where.missing] to find missing relationship records.
0 commit comments