Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

document ActiveRecord's except and only

Document methods that allow easily override arel queries
  • Loading branch information...
commit b31ef7ee83f3fe808f7534172ce2bf22ef6c7cc0 1 parent da82b0a
@jrom jrom authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 activerecord/lib/active_record/relation/spawn_methods.rb
View
14 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -61,6 +61,13 @@ def merge(r)
alias :& :merge
+ # Removes from the query the condition(s) specified in +skips+.
+ #
+ # Example:
+ #
+ # Post.order('id asc').except(:order) # discards the order condition
+ # Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order
+ #
def except(*skips)
result = self.class.new(@klass, table)
@@ -75,6 +82,13 @@ def except(*skips)
result
end
+ # Removes any condition from the query other than the one(s) specified in +onlies+.
+ #
+ # Example:
+ #
+ # Post.order('id asc').only(:where) # discards the order condition
+ # Post.order('id asc').only(:where, :order) # uses the specified order
+ #
def only(*onlies)
result = self.class.new(@klass, table)
Please sign in to comment.
Something went wrong with that request. Please try again.