Skip to content

Commit

Permalink
Merge pull request #320 from ydah/add_finding_orphan_records
Browse files Browse the repository at this point in the history
Add "Finding missing relationship records" rule
  • Loading branch information
koic authored Jun 29, 2022
2 parents 43a9832 + d63886d commit f31e7a1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,19 @@ User.where("id != ?", id)
User.where.not(id: id)
----

=== Finding missing relationship records [[finding-missing-relationship-records]]

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.

[source,ruby]
----
# bad
Post.left_joins(:author).where(authors: { id: nil })
# good
Post.where.missing(:author)
----

=== Order by `id` [[order-by-id]]

Don't use the `id` column for ordering.
Expand Down

0 comments on commit f31e7a1

Please sign in to comment.