Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use args.flatten! in query methods when applicable

Try to use more destructive methods on *args when applicable, to avoid
creating new objects.
  • Loading branch information...
commit 755d1636107f814c6e0f76e7b3f327b9b4bdcc07 1 parent 9e1a199
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 12 additions and 7 deletions.
  1. +12 −7 activerecord/lib/active_record/relation/query_methods.rb
View
19 activerecord/lib/active_record/relation/query_methods.rb
@@ -83,7 +83,9 @@ def references(*args)
end
def references!(*args)
- self.references_values = (references_values + args.flatten.map(&:to_s)).uniq
+ args.flatten!
+
+ self.references_values = (references_values + args.map!(&:to_s)).uniq
self
end
@@ -134,7 +136,9 @@ def group(*args)
end
def group!(*args)
- self.group_values += args.flatten
+ args.flatten!
+
+ self.group_values += args
self
end
@@ -143,11 +147,10 @@ def order(*args)
end
def order!(*args)
- args = args.flatten
+ args.flatten!
references = args.reject { |arg| Arel::Node === arg }
- .map { |arg| arg =~ /^([a-zA-Z]\w*)\.(\w+)/ && $1 }
- .compact
+ references.map! { |arg| arg =~ /^([a-zA-Z]\w*)\.(\w+)/ && $1 }.compact!
references!(references) if references.any?
self.order_values += args
@@ -168,8 +171,10 @@ def reorder(*args)
end
def reorder!(*args)
+ args.flatten!
+
self.reordering_value = true
- self.order_values = args.flatten
+ self.order_values = args
self
end
@@ -327,7 +332,7 @@ def limit!(value)
#
# Should be used with order.
#
- # User.offset(10).order("name ASC")
+ # User.offset(10).order("name ASC")
def offset(value)
spawn.offset!(value)
end
Please sign in to comment.
Something went wrong with that request. Please try again.