Skip to content

Commit f31e7a1

Browse files
authored
Merge pull request #320 from ydah/add_finding_orphan_records
Add "Finding missing relationship records" rule
2 parents 43a9832 + d63886d commit f31e7a1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,19 @@ User.where("id != ?", id)
938938
User.where.not(id: id)
939939
----
940940

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.
944+
945+
[source,ruby]
946+
----
947+
# bad
948+
Post.left_joins(:author).where(authors: { id: nil })
949+
950+
# good
951+
Post.where.missing(:author)
952+
----
953+
941954
=== Order by `id` [[order-by-id]]
942955

943956
Don't use the `id` column for ordering.

0 commit comments

Comments
 (0)