aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/association.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/association.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index f1a9f254b1..fd939ab9ba 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -22,6 +22,49 @@ module ActiveRecord::Associations::Builder
else
@scope = nil
@options = scope
+
+ convert_deprecated_options_to_scope!
+ end
+ end
+
+ # FIXME: references should not be in this list
+ DEPRECATED_OPTIONS = [:readonly, :references, :order, :limit, :joins, :group, :having,
+ :offset, :select, :uniq, :include, :conditions]
+
+ class DeprecatedOptionsProc
+ attr_reader :options
+
+ def initialize(options)
+ @options = options
+ end
+
+ def to_proc
+ options = self.options
+ proc do |owner|
+ if options[:where].respond_to?(:to_proc)
+ context = owner || self
+ where(context.instance_eval(&options[:where]))
+ .merge!(options.except(:where))
+ else
+ scoped(options)
+ end
+ end
+ end
+
+ def arity
+ 1
+ end
+ end
+
+ def convert_deprecated_options_to_scope!
+ deprecated_options = options.slice(*DEPRECATED_OPTIONS)
+
+ unless deprecated_options.empty?
+ deprecated_options[:includes] = deprecated_options.delete(:include) if deprecated_options[:include]
+ deprecated_options[:where] = deprecated_options.delete(:conditions) if deprecated_options[:conditions]
+
+ @scope = DeprecatedOptionsProc.new(deprecated_options)
+ @options = options.except(*DEPRECATED_OPTIONS)
end
end