aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-07-06 18:20:20 +0100
committerJon Leighton <j@jonathanleighton.com>2012-07-13 16:23:06 +0100
commit65843e1acc0c8d285ff79f8c9c49d4d1215440be (patch)
tree57b18ebd21fe659d82476bb435c04de9964ca308 /activerecord/lib/active_record/associations/builder
parent76d33970612383c8a3c3a320c544ecbee2f38e1c (diff)
downloadrails-65843e1acc0c8d285ff79f8c9c49d4d1215440be.tar.gz
rails-65843e1acc0c8d285ff79f8c9c49d4d1215440be.tar.bz2
rails-65843e1acc0c8d285ff79f8c9c49d4d1215440be.zip
Represent association scope options as AR::Relations insternally.
Diffstat (limited to 'activerecord/lib/active_record/associations/builder')
-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