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 d853fd63d1..5cea2328e8 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -20,9 +20,7 @@ module ActiveRecord table = Arel::Table.new(table_name, :engine => @engine) end - unless attribute = table[column] - raise StatementInvalid, "No attribute named `#{column}` exists for table `#{table.name}`" - end + attribute = table[column] || Arel::Attribute.new(table, column) case value when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 015ca8c24c..4692271266 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -15,12 +15,10 @@ module ActiveRecord end def eager_load(*args) - args.reject! { |a| a.blank? } clone.tap { |r| r.eager_load_values += args if args.present? } end def preload(*args) - args.reject! { |a| a.blank? } clone.tap { |r| r.preload_values += args if args.present? } end @@ -28,29 +26,24 @@ module ActiveRecord if block_given? to_a.select { |*block_args| yield(*block_args) } else - args.reject! { |a| a.blank? } clone.tap { |r| r.select_values += args if args.present? } end end def group(*args) - args.reject! { |a| a.blank? } clone.tap { |r| r.group_values += args if args.present? } end def order(*args) - args.reject! { |a| a.blank? } clone.tap { |r| r.order_values += args if args.present? } end def reorder(*args) - args.reject! { |a| a.blank? } clone.tap { |r| r.order_values = args if args.present? } end def joins(*args) args.flatten! - args.reject! { |a| a.blank? } clone.tap { |r| r.joins_values += args if args.present? } end @@ -93,8 +86,9 @@ module ActiveRecord clone.tap { |r| r.from_value = value } end - def extending(*modules) - clone.tap { |r| r.send :apply_modules, *modules } + def extending(*modules, &block) + modules << Module.new(&block) if block_given? + clone.tap { |r| r.send(:apply_modules, *modules) } end def reverse_order @@ -201,7 +195,7 @@ module ActiveRecord stashed_association_joins = joins.select {|j| j.is_a?(ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation)} - non_association_joins = (joins - association_joins - stashed_association_joins).reject {|j| j.blank?} + non_association_joins = (joins - association_joins - stashed_association_joins) custom_joins = custom_join_sql(*non_association_joins) join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, custom_joins) diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index bb1f138f5b..7712ad2569 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -6,7 +6,7 @@ module ActiveRecord merged_relation = clone return merged_relation unless r - (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS).reject {|m| [:joins, :where].include?(m)}.each do |method| + ((Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS) - [:joins, :where]).each do |method| value = r.send(:"#{method}_values") merged_relation.send(:"#{method}_values=", value) if value.present? end |