Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve where chaining docs [ci-skip] #45352

Merged
merged 1 commit into from Jun 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -10,10 +10,10 @@ module ActiveRecord
module QueryMethods
include ActiveModel::ForbiddenAttributesProtection

# WhereChain objects act as placeholder for queries in which #where does not have any parameter.
# In this case, #where must be chained with #not to return a new relation.
# WhereChain objects act as placeholder for queries in which +where+ does not have any parameter.
# In this case, +where+ can be chained to return a new relation.
class WhereChain
def initialize(scope)
def initialize(scope) # :nodoc:
@scope = scope
end

Expand Down Expand Up @@ -722,12 +722,26 @@ def left_outer_joins!(*args) # :nodoc:
# === no argument
#
# If no argument is passed, #where returns a new instance of WhereChain, that
# can be chained with #not to return a new relation that negates the where clause.
# can be chained with WhereChain#not, WhereChain#missing, or WhereChain#associated.
#
# Chaining with WhereChain#not:
#
# User.where.not(name: "Jon")
# # SELECT * FROM users WHERE name != 'Jon'
#
# See WhereChain for more details on #not.
# Chaining with WhereChain#associated:
#
# Post.where.associated(:author)
# # SELECT "posts".* FROM "posts"
# # INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
# # WHERE "authors"."id" IS NOT NULL
#
# Chaining with WhereChain#missing:
#
# Post.where.missing(:author)
# # SELECT "posts".* FROM "posts"
# # LEFT OUTER JOIN "authors" ON "authors"."id" = "posts"."author_id"
# # WHERE "authors"."id" IS NULL
#
# === blank condition
#
Expand Down