diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-16 21:21:20 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-16 21:21:20 +0530 |
commit | 61e831564aa4b22983646ecdc15d43991bc0e522 (patch) | |
tree | d14aacd07e87a9331241a295b46ff6fbd5d60aa4 | |
parent | 488b4c8c5c8e441c0aaaa9d4f71263dd3beacde4 (diff) | |
download | rails-61e831564aa4b22983646ecdc15d43991bc0e522.tar.gz rails-61e831564aa4b22983646ecdc15d43991bc0e522.tar.bz2 rails-61e831564aa4b22983646ecdc15d43991bc0e522.zip |
Add Relation#apply_finder_options for applying old finder options
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 30 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 23 |
2 files changed, 24 insertions, 29 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e84130f42e..5bd24ac3eb 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1563,24 +1563,8 @@ module ActiveRecord #:nodoc: end def construct_finder_arel(options = {}, scope = nil) - validate_find_options(options) - - relation = active_relation. - joins(options[:joins]). - where(options[:conditions]). - select(options[:select]). - group(options[:group]). - having(options[:having]). - order(options[:order]). - limit(options[:limit]). - offset(options[:offset]). - from(options[:from]). - includes(options[:include]) - + relation = active_relation.apply_finder_options(options) relation = relation.where(type_condition) if finder_needs_type_condition? - relation = relation.lock(options[:lock]) if options[:lock].present? - relation = relation.readonly(options[:readonly]) if options.has_key?(:readonly) - relation = scope.merge(relation) if scope relation end @@ -1781,11 +1765,6 @@ module ActiveRecord #:nodoc: end method_scoping.assert_valid_keys([ :find, :create ]) - - if f = method_scoping[:find] - f.assert_valid_keys(VALID_FIND_OPTIONS) - end - relation = construct_finder_arel(method_scoping[:find] || {}) if current_scoped_methods && current_scoped_methods.create_with_value && method_scoping[:create] @@ -2047,13 +2026,6 @@ module ActiveRecord #:nodoc: end end - VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, - :order, :select, :readonly, :group, :having, :from, :lock ] - - def validate_find_options(options) #:nodoc: - options.assert_valid_keys(VALID_FIND_OPTIONS) - end - def encode_quoted_value(value) #:nodoc: quoted_value = connection.quote(value) quoted_value = "'#{quoted_value[1..-2].gsub(/\'/, "\\\\'")}'" if quoted_value.include?("\\\'") # (for ruby mode) " diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index a248c72715..59cfca85ae 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -88,5 +88,28 @@ module ActiveRecord result end + VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, + :order, :select, :readonly, :group, :having, :from, :lock ] + + def apply_finder_options(options) + options.assert_valid_keys(VALID_FIND_OPTIONS) + + relation = joins(options[:joins]). + where(options[:conditions]). + select(options[:select]). + group(options[:group]). + having(options[:having]). + order(options[:order]). + limit(options[:limit]). + offset(options[:offset]). + from(options[:from]). + includes(options[:include]) + + relation = relation.lock(options[:lock]) if options[:lock].present? + relation = relation.readonly(options[:readonly]) if options.has_key?(:readonly) + + relation + end + end end |