diff options
author | Xavier Noria <fxn@hashref.com> | 2010-07-31 11:55:24 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-07-31 11:55:24 +0200 |
commit | 3d7099891f07395ed889e7da9e13b3ff9244d539 (patch) | |
tree | 6a988362ec4a6b58c90a12e6b715cd6926a111ce /activerecord/lib/active_record/relation/query_methods.rb | |
parent | 0e20e3ebc20250174867f33e0ad3972f7e7c76d0 (diff) | |
parent | d3819daaac0d2f730f2b34af31700c914e697375 (diff) | |
download | rails-3d7099891f07395ed889e7da9e13b3ff9244d539.tar.gz rails-3d7099891f07395ed889e7da9e13b3ff9244d539.tar.bz2 rails-3d7099891f07395ed889e7da9e13b3ff9244d539.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 716e7275a5..a92d180442 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -47,8 +47,8 @@ module ActiveRecord clone.tap {|r| r.joins_values += args if args.present? } end - def where(opts, other = nil) - value = build_where(opts, other) + def where(opts, *rest) + value = build_where(opts, rest) value ? clone.tap {|r| r.where_values += Array.wrap(value) } : clone end @@ -129,7 +129,7 @@ module ActiveRecord def build_arel arel = table - arel = build_joins(arel, @joins_values) if @joins_values.present? + arel = build_joins(arel, @joins_values) unless @joins_values.empty? @where_values.uniq.each do |where| next if where.blank? @@ -143,33 +143,27 @@ module ActiveRecord end end - arel = arel.having(*@having_values.uniq.select{|h| h.present?}) if @having_values.present? + arel = arel.having(*@having_values.uniq.select{|h| h.present?}) unless @having_values.empty? - arel = arel.take(@limit_value) if @limit_value.present? - arel = arel.skip(@offset_value) if @offset_value.present? + arel = arel.take(@limit_value) if @limit_value + arel = arel.skip(@offset_value) if @offset_value - arel = arel.group(*@group_values.uniq.select{|g| g.present?}) if @group_values.present? + arel = arel.group(*@group_values.uniq.select{|g| g.present?}) unless @group_values.empty? - arel = arel.order(*@order_values.uniq.select{|o| o.present?}) if @order_values.present? + arel = arel.order(*@order_values.uniq.select{|o| o.present?}) unless @order_values.empty? arel = build_select(arel, @select_values.uniq) - arel = arel.from(@from_value) if @from_value.present? - - case @lock_value - when TrueClass - arel = arel.lock - when String - arel = arel.lock(@lock_value) - end if @lock_value.present? + arel = arel.from(@from_value) if @from_value + arel = arel.lock(@lock_value) if @lock_value arel end - def build_where(opts, other = nil) + def build_where(opts, other = []) case opts when String, Array - @klass.send(:sanitize_sql, other ? [opts, other] : opts) + @klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other)) when Hash attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts) PredicateBuilder.new(table.engine).build_from_hash(attributes, table) |