diff options
Diffstat (limited to 'activerecord/lib/active_record/relation')
3 files changed, 6 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 61d9974570..9633fd3d82 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -18,7 +18,10 @@ module ActiveRecord attribute = table[column.to_sym] case value - when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation + when ActiveRecord::Relation + value.select_values = [value.klass.arel_table['id']] if value.select_values.empty? + attribute.in(value.arel.ast) + when Array, ActiveRecord::Associations::CollectionProxy values = value.to_a.map { |x| x.is_a?(ActiveRecord::Base) ? x.id : x } diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 2cbb103eb9..f76681e880 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -171,7 +171,7 @@ module ActiveRecord arel.having(*@having_values.uniq.reject{|h| h.blank?}) unless @having_values.empty? - arel.take(@limit_value) if @limit_value + arel.take(connection.sanitize_limit(@limit_value)) if @limit_value arel.skip(@offset_value) if @offset_value arel.group(*@group_values.uniq.reject{|g| g.blank?}) unless @group_values.empty? @@ -209,16 +209,7 @@ module ActiveRecord def collapse_wheres(arel, wheres) equalities = wheres.grep(Arel::Nodes::Equality) - groups = equalities.group_by do |equality| - equality.left - end - - groups.each do |_, eqls| - test = eqls.inject(eqls.shift) do |memo, expr| - memo.or(expr) - end - arel.where(test) - end + arel.where(Arel::Nodes::And.new(equalities)) unless equalities.empty? (wheres - equalities).each do |where| where = Arel.sql(where) if String === where diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 69a7642ec5..4150e36a9a 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -61,8 +61,6 @@ module ActiveRecord merged_relation end - alias :& :merge - # Removes from the query the condition(s) specified in +skips+. # # Example: |