diff options
-rw-r--r-- | Gemfile | 6 | ||||
-rw-r--r-- | activerecord/activerecord.gemspec | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/belongs_to_association.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 22 |
7 files changed, 16 insertions, 30 deletions
@@ -18,6 +18,12 @@ else gem 'journey', :git => "git://github.com/rails/journey" end +if ENV['AR_DEPRECATED_FINDERS'] + gem 'active_record_deprecated_finders', path: ENV['AR_DEPRECATED_FINDERS'] +else + gem 'active_record_deprecated_finders', git: 'git://github.com/rails/active_record_deprecated_finders' +end + # This needs to be with require false to avoid # it being automatically loaded by sprockets gem 'uglifier', '>= 1.0.3', :require => false diff --git a/activerecord/activerecord.gemspec b/activerecord/activerecord.gemspec index 26eb74df0f..e8e5f4adfe 100644 --- a/activerecord/activerecord.gemspec +++ b/activerecord/activerecord.gemspec @@ -22,4 +22,6 @@ Gem::Specification.new do |s| s.add_dependency('activesupport', version) s.add_dependency('activemodel', version) s.add_dependency('arel', '~> 3.0.2') + + s.add_dependency('active_record_deprecated_finders', '0.0.1') end diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 0cb0644bcf..c4b10a8dae 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -25,6 +25,7 @@ require 'active_support' require 'active_support/i18n' require 'active_model' require 'arel' +require 'active_record_deprecated_finders' require 'active_record/version' diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 3c41a303d3..4e09a43f8e 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -25,10 +25,7 @@ module ActiveRecord def initialize(owner, reflection) reflection.check_validity! - @target = nil @owner, @reflection = owner, reflection - @updated = false - @stale_state = nil reset reset_scope @@ -46,6 +43,7 @@ module ActiveRecord def reset @loaded = false @target = nil + @stale_state = nil end # Reloads the \target and returns +self+ on success. @@ -215,10 +213,6 @@ module ActiveRecord def stale_state end - def association_class - @reflection.klass - end - def build_record(attributes, options) reflection.build_association(attributes, options) do |record| attributes = create_scope.except(*(record.changed - [reflection.foreign_key])) diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 97f531d064..81c6e400d2 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -14,6 +14,11 @@ module ActiveRecord self.target = record end + def reset + super + @updated = false + end + def updated? @updated end diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index da4c311bce..14aa557b6c 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -71,7 +71,7 @@ module ActiveRecord end def reset - @loaded = false + super @target = [] end diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 03ba8c8628..19ec41e5ca 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -128,27 +128,5 @@ module ActiveRecord result end - VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, :extend, :references, - :order, :select, :readonly, :group, :having, :from, :lock ] - - def apply_finder_options(options) - relation = clone - return relation unless options - - options.assert_valid_keys(VALID_FIND_OPTIONS) - finders = options.dup - finders.delete_if { |key, value| value.nil? && key != :limit } - - ((VALID_FIND_OPTIONS - [:conditions, :include, :extend]) & finders.keys).each do |finder| - relation = relation.send(finder, finders[finder]) - end - - relation = relation.where(finders[:conditions]) if options.has_key?(:conditions) - relation = relation.includes(finders[:include]) if options.has_key?(:include) - relation = relation.extending(finders[:extend]) if options.has_key?(:extend) - - relation - end - end end |