aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2010-04-04 17:34:23 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2010-04-04 17:34:23 +0100
commit00884a59013a658082dab41da5ff41add31b8c43 (patch)
tree666b862b08b04c7a3727ee22b2cd1a2561af4e52 /activerecord/lib
parent48b2451142355b22de5f8130b3debdd4e53e2ba2 (diff)
parent7d7e0627a0490b6b4ddb0ee5429264ccd46f1245 (diff)
downloadrails-00884a59013a658082dab41da5ff41add31b8c43.tar.gz
rails-00884a59013a658082dab41da5ff41add31b8c43.tar.bz2
rails-00884a59013a658082dab41da5ff41add31b8c43.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb73
-rw-r--r--activerecord/lib/active_record/associations/through_association_scope.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb3
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb6
-rw-r--r--activerecord/lib/active_record/named_scope.rb133
-rw-r--r--activerecord/lib/active_record/railties/databases.rake2
-rw-r--r--activerecord/lib/active_record/reflection.rb11
-rw-r--r--activerecord/lib/active_record/relation.rb21
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb20
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb6
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb25
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb15
-rw-r--r--activerecord/lib/active_record/version.rb2
13 files changed, 141 insertions, 178 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 7406daf837..20a8754b7c 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1495,14 +1495,6 @@ module ActiveRecord
# finder conditions.
def configure_dependency_for_has_many(reflection, extra_conditions = nil)
if reflection.options.include?(:dependent)
- # Add polymorphic type if the :as option is present
- dependent_conditions = []
- dependent_conditions << "#{reflection.primary_key_name} = \#{record.#{reflection.name}.send(:owner_quoted_id)}"
- dependent_conditions << "#{reflection.options[:as]}_type = '#{base_class.name}'" if reflection.options[:as]
- dependent_conditions << sanitize_sql(reflection.options[:conditions], reflection.table_name) if reflection.options[:conditions]
- dependent_conditions << extra_conditions if extra_conditions
- dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ")
- dependent_conditions = dependent_conditions.gsub('@', '\@')
case reflection.options[:dependent]
when :destroy
method_name = "has_many_dependent_destroy_for_#{reflection.name}".to_sym
@@ -1511,51 +1503,30 @@ module ActiveRecord
end
before_destroy method_name
when :delete_all
- # before_destroy do |record|
- # self.class.send(:delete_all_has_many_dependencies,
- # record,
- # "posts",
- # Post,
- # %@...@) # this is a string literal like %(...)
- # end
- # end
- module_eval <<-CALLBACK
- before_destroy do |record|
- self.class.send(:delete_all_has_many_dependencies,
- record,
- "#{reflection.name}",
- #{reflection.class_name},
- %@#{dependent_conditions}@)
- end
- CALLBACK
+ before_destroy do |record|
+ self.class.send(:delete_all_has_many_dependencies,
+ record,
+ reflection.name,
+ reflection.klass,
+ reflection.dependent_conditions(record, self.class, extra_conditions))
+ end
when :nullify
- # before_destroy do |record|
- # self.class.send(:nullify_has_many_dependencies,
- # record,
- # "posts",
- # Post,
- # "user_id",
- # %@...@) # this is a string literal like %(...)
- # end
- # end
- module_eval <<-CALLBACK
- before_destroy do |record|
- self.class.send(:nullify_has_many_dependencies,
- record,
- "#{reflection.name}",
- #{reflection.class_name},
- "#{reflection.primary_key_name}",
- %@#{dependent_conditions}@)
- end
- CALLBACK
- when :restrict
- method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym
- define_method(method_name) do
- unless send(reflection.name).empty?
- raise DeleteRestrictionError.new(reflection)
- end
+ before_destroy do |record|
+ self.class.send(:nullify_has_many_dependencies,
+ record,
+ reflection.name,
+ reflection.klass,
+ reflection.primary_key_name,
+ reflection.dependent_conditions(record, self.class, extra_conditions))
+ end
+ when :restrict
+ method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym
+ define_method(method_name) do
+ unless send(reflection.name).empty?
+ raise DeleteRestrictionError.new(reflection)
end
- before_destroy method_name
+ end
+ before_destroy method_name
else
raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, :nullify or :restrict (#{reflection.options[:dependent].inspect})"
end
diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb
index 6f0f698f1e..1d2f323112 100644
--- a/activerecord/lib/active_record/associations/through_association_scope.rb
+++ b/activerecord/lib/active_record/associations/through_association_scope.rb
@@ -135,7 +135,7 @@ module ActiveRecord
def build_through_conditions
conditions = @reflection.through_reflection.options[:conditions]
if conditions.is_a?(Hash)
- interpolate_sql(sanitize_sql(conditions)).gsub(
+ interpolate_sql(@reflection.through_reflection.klass.send(:sanitize_sql, conditions)).gsub(
@reflection.quoted_table_name,
@reflection.through_reflection.quoted_table_name)
elsif conditions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 046825d43f..6c477e48ce 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -23,7 +23,8 @@ module ActiveRecord
#
# +name+ is the column's name, such as <tt>supplier_id</tt> in <tt>supplier_id int(11)</tt>.
# +default+ is the type-casted default value, such as +new+ in <tt>sales_stage varchar(20) default 'new'</tt>.
- # +sql_type+ is only used to extract the column's length, if necessary. For example +60+ in <tt>company_name varchar(60)</tt>.
+ # +sql_type+ is used to extract the column's length, if necessary. For example +60+ in <tt>company_name varchar(60)</tt>.
+ # It will be mapped to one of the standard Rails SQL types in the <tt>type</tt> attribute.
# +null+ determines if this column allows +NULL+ values.
def initialize(name, default, sql_type = nil, null = true)
@name, @sql_type, @null = name, sql_type, null
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index a6042e1382..2395a744a3 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -114,6 +114,12 @@ module ActiveRecord
# Object identifier types
when /^oid$/
:integer
+ # UUID type
+ when /^uuid$/
+ :string
+ # Small and big integer types
+ when /^(?:small|big)int$/
+ :integer
# Pass through all types that are not specific to PostgreSQL.
else
super
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 9abf979cd0..632322b517 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -8,16 +8,15 @@ module ActiveRecord
extend ActiveSupport::Concern
module ClassMethods
- # Returns a relation if invoked without any arguments.
+ # Returns an anonymous scope.
#
# posts = Post.scoped
# posts.size # Fires "select count(*) from posts" and returns the count
# posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects
#
- # Returns an anonymous named scope if any options are supplied.
- #
- # shirts = Shirt.scoped(:conditions => {:color => 'red'})
- # shirts = shirts.scoped(:include => :washing_instructions)
+ # fruits = Fruit.scoped
+ # fruits = fruits.where(:colour => 'red') if options[:red_only]
+ # fruits = fruits.limit(10) if limited?
#
# Anonymous \scopes tend to be useful when procedurally generating complex queries, where passing
# intermediate values (scopes) around as first-class objects is convenient.
@@ -25,7 +24,8 @@ module ActiveRecord
# You can define a scope that applies to all finders using ActiveRecord::Base.default_scope.
def scoped(options = {}, &block)
if options.present?
- Scope.init(self, options, &block)
+ relation = scoped.apply_finder_options(options)
+ block_given? ? relation.extending(Module.new(&block)) : relation
else
current_scoped_methods ? unscoped.merge(current_scoped_methods) : unscoped.clone
end
@@ -36,21 +36,21 @@ module ActiveRecord
end
# Adds a class method for retrieving and querying objects. A scope represents a narrowing of a database query,
- # such as <tt>:conditions => {:color => :red}, :select => 'shirts.*', :include => :washing_instructions</tt>.
+ # such as <tt>where(:color => :red).select('shirts.*').includes(:washing_instructions)</tt>.
#
# class Shirt < ActiveRecord::Base
- # scope :red, :conditions => {:color => 'red'}
- # scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true]
+ # scope :red, where(:color => 'red')
+ # scope :dry_clean_only, joins(:washing_instructions).where('washing_instructions.dry_clean_only = ?', true)
# end
#
# The above calls to <tt>scope</tt> define class methods Shirt.red and Shirt.dry_clean_only. Shirt.red,
- # in effect, represents the query <tt>Shirt.find(:all, :conditions => {:color => 'red'})</tt>.
+ # in effect, represents the query <tt>Shirt.where(:color => 'red')</tt>.
#
# Unlike <tt>Shirt.find(...)</tt>, however, the object returned by Shirt.red is not an Array; it resembles the association object
- # constructed by a <tt>has_many</tt> declaration. For instance, you can invoke <tt>Shirt.red.find(:first)</tt>, <tt>Shirt.red.count</tt>,
- # <tt>Shirt.red.find(:all, :conditions => {:size => 'small'})</tt>. Also, just
- # as with the association objects, named \scopes act like an Array, implementing Enumerable; <tt>Shirt.red.each(&block)</tt>,
- # <tt>Shirt.red.first</tt>, and <tt>Shirt.red.inject(memo, &block)</tt> all behave as if Shirt.red really was an Array.
+ # constructed by a <tt>has_many</tt> declaration. For instance, you can invoke <tt>Shirt.red.first</tt>, <tt>Shirt.red.count</tt>,
+ # <tt>Shirt.red.where(:size => 'small')</tt>. Also, just as with the association objects, named \scopes act like an Array,
+ # implementing Enumerable; <tt>Shirt.red.each(&block)</tt>, <tt>Shirt.red.first</tt>, and <tt>Shirt.red.inject(memo, &block)</tt>
+ # all behave as if Shirt.red really was an Array.
#
# These named \scopes are composable. For instance, <tt>Shirt.red.dry_clean_only</tt> will produce all shirts that are both red and dry clean only.
# Nested finds and calculations also work with these compositions: <tt>Shirt.red.dry_clean_only.count</tt> returns the number of garments
@@ -69,9 +69,7 @@ module ActiveRecord
# Named \scopes can also be procedural:
#
# class Shirt < ActiveRecord::Base
- # scope :colored, lambda { |color|
- # { :conditions => { :color => color } }
- # }
+ # scope :colored, lambda {|color| where(:color => color) }
# end
#
# In this example, <tt>Shirt.colored('puce')</tt> finds all puce shirts.
@@ -79,26 +77,13 @@ module ActiveRecord
# Named \scopes can also have extensions, just as with <tt>has_many</tt> declarations:
#
# class Shirt < ActiveRecord::Base
- # scope :red, :conditions => {:color => 'red'} do
+ # scope :red, where(:color => 'red') do
# def dom_id
# 'red_shirts'
# end
# end
# end
- #
- #
- # For testing complex named \scopes, you can examine the scoping options using the
- # <tt>proxy_options</tt> method on the proxy itself.
- #
- # class Shirt < ActiveRecord::Base
- # scope :colored, lambda { |color|
- # { :conditions => { :color => color } }
- # }
- # end
- #
- # expected_options = { :conditions => { :colored => 'red' } }
- # assert_equal expected_options, Shirt.colored('red').proxy_options
- def scope(name, options = {}, &block)
+ def scope(name, scope_options = {}, &block)
name = name.to_sym
if !scopes[name] && respond_to?(name, true)
@@ -106,17 +91,17 @@ module ActiveRecord
"Overwriting existing method #{self.name}.#{name}."
end
- scopes[name] = lambda do |parent_scope, *args|
- Scope.init(parent_scope, case options
- when Hash, Relation
- options
- when Proc
- options.call(*args)
- end, &block)
+ scopes[name] = lambda do |*args|
+ options = scope_options.is_a?(Proc) ? scope_options.call(*args) : scope_options
+
+ relation = scoped
+ relation = options.is_a?(Hash) ? relation.apply_finder_options(options) : scoped.merge(options) if options
+ block_given? ? relation.extending(Module.new(&block)) : relation
end
+
singleton_class.instance_eval do
define_method name do |*args|
- scopes[name].call(self, *args)
+ scopes[name].call(*args)
end
end
end
@@ -127,73 +112,5 @@ module ActiveRecord
end
end
- class Scope < Relation
- attr_accessor :current_scoped_methods_when_defined
-
- delegate :scopes, :with_scope, :with_exclusive_scope, :scoped_methods, :scoped, :to => :klass
-
- def self.init(klass, options, &block)
- relation = new(klass, klass.arel_table)
-
- scope = if options.is_a?(Hash)
- klass.scoped.apply_finder_options(options.except(:extend))
- else
- options ? klass.scoped.merge(options) : klass.scoped
- end
-
- relation = relation.merge(scope)
-
- Array.wrap(options[:extend]).each {|extension| relation.send(:extend, extension) } if options.is_a?(Hash)
- relation.send(:extend, Module.new(&block)) if block_given?
-
- relation.current_scoped_methods_when_defined = klass.send(:current_scoped_methods)
- relation
- end
-
- def first(*args)
- if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash))
- to_a.first(*args)
- else
- args.first.present? ? apply_finder_options(args.first).first : super
- end
- end
-
- def last(*args)
- if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash))
- to_a.last(*args)
- else
- args.first.present? ? apply_finder_options(args.first).last : super
- end
- end
-
- def ==(other)
- case other
- when Scope
- to_sql == other.to_sql
- when Relation
- other == self
- when Array
- to_a == other.to_a
- end
- end
-
- private
-
- def method_missing(method, *args, &block)
- if klass.respond_to?(method)
- with_scope(self) do
- if current_scoped_methods_when_defined && !scoped_methods.include?(current_scoped_methods_when_defined) && !scopes.include?(method)
- with_scope(current_scoped_methods_when_defined) { klass.send(method, *args, &block) }
- else
- klass.send(method, *args, &block)
- end
- end
- else
- super
- end
- end
-
- end
-
end
end
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 06485b9033..a107befef3 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -84,7 +84,7 @@ namespace :db do
end
end
when 'postgresql'
- @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
+ @encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'
schema_search_path = config['schema_search_path'] || 'public'
first_in_schema_search_path = schema_search_path.split(',').first.strip
begin
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 5e8fc104cb..0e48e229b3 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -277,6 +277,17 @@ module ActiveRecord
!options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many)
end
+ def dependent_conditions(record, base_class, extra_conditions)
+ dependent_conditions = []
+ dependent_conditions << "#{primary_key_name} = #{record.send(name).send(:owner_quoted_id)}"
+ dependent_conditions << "#{options[:as]}_type = '#{base_class.name}'" if options[:as]
+ dependent_conditions << klass.send(:sanitize_sql, options[:conditions]) if options[:conditions]
+ dependent_conditions << extra_conditions if extra_conditions
+ dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ")
+ dependent_conditions = dependent_conditions.gsub('@', '\@')
+ dependent_conditions
+ end
+
private
def derive_class_name
class_name = name.to_s.camelize
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 8577ec58f7..4e62187449 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -13,8 +13,9 @@ module ActiveRecord
delegate :insert, :to => :arel
attr_reader :table, :klass
+ attr_accessor :extensions
- def initialize(klass, table)
+ def initialize(klass, table, &block)
@klass, @table = klass, table
@implicit_readonly = nil
@@ -22,6 +23,9 @@ module ActiveRecord
SINGLE_VALUE_METHODS.each {|v| instance_variable_set(:"@#{v}_value", nil)}
(ASSOCIATION_METHODS + MULTI_VALUE_METHODS).each {|v| instance_variable_set(:"@#{v}_values", [])}
+ @extensions = []
+
+ apply_modules(Module.new(&block)) if block_given?
end
def new(*args, &block)
@@ -307,11 +311,26 @@ module ActiveRecord
@should_eager_load ||= (@eager_load_values.any? || (@includes_values.any? && references_eager_loaded_tables?))
end
+ def ==(other)
+ case other
+ when Relation
+ other.to_sql == to_sql
+ when Array
+ to_a == other.to_a
+ end
+ end
+
+ def inspect
+ to_a.inspect
+ end
+
protected
def method_missing(method, *args, &block)
if Array.method_defined?(method)
to_a.send(method, *args, &block)
+ elsif @klass.scopes[method]
+ merge(@klass.send(method, *args, &block))
elsif @klass.respond_to?(method)
@klass.send(:with_scope, self) { @klass.send(method, *args, &block) }
elsif arel.respond_to?(method)
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 37aaac0894..a26f1c0ac8 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -106,13 +106,29 @@ module ActiveRecord
# A convenience wrapper for <tt>find(:first, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:first)</tt>.
def first(*args)
- args.any? ? apply_finder_options(args.first).first : find_first
+ if args.any?
+ if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash))
+ to_a.first(*args)
+ else
+ apply_finder_options(args.first).first
+ end
+ else
+ find_first
+ end
end
# A convenience wrapper for <tt>find(:last, *args)</tt>. You can pass in all the
# same arguments to this method as you can to <tt>find(:last)</tt>.
def last(*args)
- args.any? ? apply_finder_options(args.first).last : find_last
+ if args.any?
+ if args.first.kind_of?(Integer) || (loaded? && !args.first.kind_of?(Hash))
+ to_a.last(*args)
+ else
+ apply_finder_options(args.first).last
+ end
+ else
+ find_last
+ end
end
# A convenience wrapper for <tt>find(:all, *args)</tt>. You can pass in all the
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 711df16bf1..d0efa2189d 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -20,10 +20,12 @@ module ActiveRecord
table = Arel::Table.new(table_name, :engine => @engine)
end
- attribute = table[column]
+ unless attribute = table[column]
+ raise StatementInvalid, "No attribute named `#{column}` exists for table `#{table.name}`"
+ end
case value
- when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope
+ when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Relation
values = value.to_a
attribute.in(values)
when Range
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index e224781016..b5e8b7570a 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -10,8 +10,9 @@ module ActiveRecord
next if [:where, :having].include?(query_method)
class_eval <<-CEVAL
- def #{query_method}(*args)
+ def #{query_method}(*args, &block)
new_relation = clone
+ new_relation.send(:apply_modules, Module.new(&block)) if block_given?
value = Array.wrap(args.flatten).reject {|x| x.blank? }
new_relation.#{query_method}_values += value if value.present?
new_relation
@@ -21,8 +22,9 @@ module ActiveRecord
[:where, :having].each do |query_method|
class_eval <<-CEVAL
- def #{query_method}(*args)
+ def #{query_method}(*args, &block)
new_relation = clone
+ new_relation.send(:apply_modules, Module.new(&block)) if block_given?
value = build_where(*args)
new_relation.#{query_method}_values += [*value] if value.present?
new_relation
@@ -34,8 +36,9 @@ module ActiveRecord
attr_accessor :"#{query_method}_value"
class_eval <<-CEVAL
- def #{query_method}(value = true)
+ def #{query_method}(value = true, &block)
new_relation = clone
+ new_relation.send(:apply_modules, Module.new(&block)) if block_given?
new_relation.#{query_method}_value = value
new_relation
end
@@ -43,8 +46,16 @@ module ActiveRecord
end
end
- def lock(locks = true)
+ def extending(*modules)
+ new_relation = clone
+ new_relation.send :apply_modules, *modules
+ new_relation
+ end
+
+ def lock(locks = true, &block)
relation = clone
+ relation.send(:apply_modules, Module.new(&block)) if block_given?
+
case locks
when String, TrueClass, NilClass
clone.tap {|new_relation| new_relation.lock_value = locks || true }
@@ -191,6 +202,12 @@ module ActiveRecord
private
+ def apply_modules(modules)
+ values = Array.wrap(modules)
+ @extensions += values if values.present?
+ values.each {|extension| extend(extension) }
+ end
+
def reverse_sql_order(order_query)
order_query.to_s.split(/,/).each { |s|
if s.match(/\s(asc|ASC)$/)
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index a17de1bdbb..8fdd64afcc 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -6,10 +6,9 @@ module ActiveRecord
merged_relation = clone
return merged_relation unless r
- (ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).reject {|m| [:joins, :where].include?(m)}.each do |method|
- unless (value = r.send(:"#{method}_values")).blank?
- merged_relation.send(:"#{method}_values=", value)
- end
+ (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS).reject {|m| [:joins, :where].include?(m)}.each do |method|
+ value = r.send(:"#{method}_values")
+ merged_relation.send(:"#{method}_values=", value) if value.present?
end
merged_relation = merged_relation.joins(r.joins_values)
@@ -26,7 +25,7 @@ module ActiveRecord
merged_relation.where_values = merged_wheres
- ActiveRecord::Relation::SINGLE_VALUE_METHODS.reject {|m| m == :lock}.each do |method|
+ Relation::SINGLE_VALUE_METHODS.reject {|m| m == :lock}.each do |method|
unless (value = r.send(:"#{method}_value")).nil?
merged_relation.send(:"#{method}_value=", value)
end
@@ -34,6 +33,9 @@ module ActiveRecord
merged_relation.lock_value = r.lock_value unless merged_relation.lock_value
+ # Apply scope extension modules
+ merged_relation.send :apply_modules, r.extensions
+
merged_relation
end
@@ -69,7 +71,7 @@ module ActiveRecord
result
end
- VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset,
+ VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, :extend,
:order, :select, :readonly, :group, :having, :from, :lock ]
def apply_finder_options(options)
@@ -84,6 +86,7 @@ module ActiveRecord
relation = relation.where(options[:conditions]) if options.has_key?(:conditions)
relation = relation.includes(options[:include]) if options.has_key?(:include)
+ relation = relation.extending(options[:extend]) if options.has_key?(:extend)
relation
end
diff --git a/activerecord/lib/active_record/version.rb b/activerecord/lib/active_record/version.rb
index eaf5dc6545..cf78ec6e12 100644
--- a/activerecord/lib/active_record/version.rb
+++ b/activerecord/lib/active_record/version.rb
@@ -3,7 +3,7 @@ module ActiveRecord
MAJOR = 3
MINOR = 0
TINY = 0
- BUILD = "beta1"
+ BUILD = "beta2"
STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
end