diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-09-03 00:17:09 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-09-03 00:17:09 +0000 |
commit | 6246fad19a5ec747f5914c142b8631af212d47ea (patch) | |
tree | 7693248f7fd9e42a69bd13b4bbb94c4ed2d576e9 /activerecord/lib | |
parent | f0dbd22c4647bf8e37fd9b58ce6652aaca27376e (diff) | |
download | rails-6246fad19a5ec747f5914c142b8631af212d47ea.tar.gz rails-6246fad19a5ec747f5914c142b8631af212d47ea.tar.bz2 rails-6246fad19a5ec747f5914c142b8631af212d47ea.zip |
Remove deprecated functionality from edge rails. Closes #9387 [lifofifo]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7402 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 61 | ||||
-rw-r--r-- | activerecord/lib/active_record/deprecated_associations.rb | 93 | ||||
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 13 |
3 files changed, 5 insertions, 162 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 5e30160445..adde221477 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -6,7 +6,6 @@ require 'active_record/associations/has_one_association' require 'active_record/associations/has_many_association' require 'active_record/associations/has_many_through_association' require 'active_record/associations/has_and_belongs_to_many_association' -require 'active_record/deprecated_associations' module ActiveRecord class HasManyThroughAssociationNotFoundError < ActiveRecordError #:nodoc: @@ -625,13 +624,7 @@ module ActiveRecord # alongside this object by calling their destroy method. If set to <tt>:delete_all</tt> all associated # objects are deleted *without* calling their destroy method. If set to <tt>:nullify</tt> all associated # objects' foreign keys are set to +NULL+ *without* calling their save callbacks. - # NOTE: <tt>:dependent => true</tt> is deprecated and has been replaced with <tt>:dependent => :destroy</tt>. # May not be set if <tt>:exclusively_dependent</tt> is also set. - # * <tt>:exclusively_dependent</tt> - Deprecated; equivalent to <tt>:dependent => :delete_all</tt>. If set to +true+ all - # the associated objects are deleted in one SQL statement without having their - # +before_destroy+ callback run. This should only be used on associations that depend solely on this class and don't need to do any - # clean-up in +before_destroy+. The upside is that it's much faster, especially if there's a +counter_cache+ involved. - # May not be set if <tt>:dependent</tt> is also set. # * <tt>:finder_sql</tt> - specify a complete SQL statement to fetch the association. This is a good way to go for complex # associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added. # * <tt>:counter_sql</tt> - specify a complete SQL statement to fetch the size of the association. If <tt>:finder_sql</tt> is @@ -680,8 +673,6 @@ module ActiveRecord add_association_callbacks(reflection.name, reflection.options) collection_accessor_methods(reflection, HasManyAssociation) end - - add_deprecated_api_for_has_many(reflection.name) end # Adds the following methods for retrieval and query of a single associated object: @@ -747,10 +738,6 @@ module ActiveRecord association_constructor_method(:create, reflection, HasOneAssociation) configure_dependency_for_has_one(reflection) - - # deprecated api - deprecated_has_association_method(reflection.name) - deprecated_association_comparison_method(reflection.name, reflection.class_name) end # Adds the following methods for retrieval and query for a single associated object for which this object holds an id: @@ -838,10 +825,6 @@ module ActiveRecord end EOF end - - # deprecated api - deprecated_has_association_method(reflection.name) - deprecated_association_comparison_method(reflection.name, reflection.class_name) end # Create the callbacks to update counter cache @@ -884,10 +867,6 @@ module ActiveRecord # An empty array is returned if none are found. # * <tt>collection<<(object, ...)</tt> - adds one or more objects to the collection by creating associations in the join table # (<tt>collection.push</tt> and <tt>collection.concat</tt> are aliases to this method). - # * <tt>collection.push_with_attributes(object, join_attributes)</tt> - adds one to the collection by creating an association in the join table that - # also holds the attributes from <tt>join_attributes</tt> (should be a hash with the column names as keys). This can be used to have additional - # attributes on the join, which will be injected into the associated objects when they are retrieved through the collection. - # (<tt>collection.concat_with_attributes</tt> is an alias to this method). This method is now deprecated. # * <tt>collection.delete(object, ...)</tt> - removes one or more objects from the collection by removing their associations from the join table. # This does not destroy the objects. # * <tt>collection=objects</tt> - replaces the collection's content by deleting and adding objects as appropriate. @@ -973,12 +952,6 @@ module ActiveRecord end_eval add_association_callbacks(reflection.name, options) - - # deprecated api - deprecated_collection_count_method(reflection.name) - deprecated_add_association_relation(reflection.name) - deprecated_remove_association_relation(reflection.name) - deprecated_has_collection_method(reflection.name) end private @@ -1141,19 +1114,6 @@ module ActiveRecord end def configure_dependency_for_has_many(reflection) - if reflection.options[:dependent] == true - ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0. Please use :dependent => :destroy instead. See http://www.rubyonrails.org/deprecation for details.", caller) - end - - if reflection.options[:dependent] && reflection.options[:exclusively_dependent] - raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options. You may specify one or the other.' - end - - if reflection.options[:exclusively_dependent] - reflection.options[:dependent] = :delete_all - ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0. Please use :dependent => :delete_all instead. See http://www.rubyonrails.org/deprecation for details.", caller) - end - # See HasManyAssociation#delete_records. Dependent associations # delete children, otherwise foreign key is set to NULL. @@ -1165,13 +1125,13 @@ module ActiveRecord dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") case reflection.options[:dependent] - when :destroy, true + when :destroy module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'" when :delete_all module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }" when :nullify module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL), %(#{dependent_conditions})) }" - when nil, false + when nil # pass else raise ArgumentError, 'The :dependent option expects either :destroy, :delete_all, or :nullify' @@ -1180,34 +1140,23 @@ module ActiveRecord def configure_dependency_for_has_one(reflection) case reflection.options[:dependent] - when :destroy, true + when :destroy module_eval "before_destroy '#{reflection.name}.destroy unless #{reflection.name}.nil?'" when :delete module_eval "before_destroy '#{reflection.class_name}.delete(#{reflection.name}.id) unless #{reflection.name}.nil?'" when :nullify module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil) unless #{reflection.name}.nil?'" - when nil, false + when nil # pass else raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify." end end - - - def add_deprecated_api_for_has_many(association_name) - deprecated_collection_count_method(association_name) - deprecated_add_association_relation(association_name) - deprecated_remove_association_relation(association_name) - deprecated_has_collection_method(association_name) - deprecated_find_in_collection_method(association_name) - deprecated_collection_create_method(association_name) - deprecated_collection_build_method(association_name) - end def create_has_many_reflection(association_id, options, &extension) options.assert_valid_keys( :class_name, :table_name, :foreign_key, - :exclusively_dependent, :dependent, + :dependent, :select, :conditions, :include, :order, :group, :limit, :offset, :as, :through, :source, :source_type, :uniq, diff --git a/activerecord/lib/active_record/deprecated_associations.rb b/activerecord/lib/active_record/deprecated_associations.rb deleted file mode 100644 index c973b65dbc..0000000000 --- a/activerecord/lib/active_record/deprecated_associations.rb +++ /dev/null @@ -1,93 +0,0 @@ -module ActiveRecord - module Associations # :nodoc: - module ClassMethods - def deprecated_collection_count_method(collection_name)# :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def #{collection_name}_count(force_reload = false) - unless has_attribute?(:#{collection_name}_count) - ActiveSupport::Deprecation.warn :#{collection_name}_count - end - #{collection_name}.reload if force_reload - #{collection_name}.size - end - end_eval - end - - def deprecated_add_association_relation(association_name)# :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def add_#{association_name}(*items) - #{association_name}.concat(items) - end - deprecate :add_#{association_name} => "use #{association_name}.concat instead" - end_eval - end - - def deprecated_remove_association_relation(association_name)# :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def remove_#{association_name}(*items) - #{association_name}.delete(items) - end - deprecate :remove_#{association_name} => "use #{association_name}.delete instead" - end_eval - end - - def deprecated_has_collection_method(collection_name)# :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def has_#{collection_name}?(force_reload = false) - !#{collection_name}(force_reload).empty? - end - deprecate :has_#{collection_name}? => "use !#{collection_name}.empty? instead" - end_eval - end - - def deprecated_find_in_collection_method(collection_name)# :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def find_in_#{collection_name}(association_id) - #{collection_name}.find(association_id) - end - deprecate :find_in_#{collection_name} => "use #{collection_name}.find instead" - end_eval - end - - def deprecated_collection_create_method(collection_name)# :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def create_in_#{collection_name}(attributes = {}) - #{collection_name}.create(attributes) - end - deprecate :create_in_#{collection_name} => "use #{collection_name}.create instead" - end_eval - end - - def deprecated_collection_build_method(collection_name)# :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def build_to_#{collection_name}(attributes = {}) - #{collection_name}.build(attributes) - end - deprecate :build_to_#{collection_name} => "use #{collection_name}.build instead" - end_eval - end - - def deprecated_association_comparison_method(association_name, association_class_name) # :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def #{association_name}?(comparison_object, force_reload = false) - if comparison_object.kind_of?(#{association_class_name}) - #{association_name}(force_reload) == comparison_object - else - raise "Comparison object is a #{association_class_name}, should have been \#{comparison_object.class.name}" - end - end - deprecate :#{association_name}? => :== - end_eval - end - - def deprecated_has_association_method(association_name) # :nodoc: - module_eval <<-"end_eval", __FILE__, __LINE__ - def has_#{association_name}?(force_reload = false) - !#{association_name}(force_reload).nil? - end - deprecate :has_#{association_name}? => "use !#{association_name} insead" - end_eval - end - end - end -end diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index f259c2bbb6..7de391f6fa 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -83,19 +83,6 @@ module ActiveRecord end end - # Will add an error message to each of the attributes in +attributes+ that has a length outside of the passed boundary +range+. - # If the length is above the boundary, the too_long_msg message will be used. If below, the too_short_msg. - def add_on_boundary_breaking(attributes, range, too_long_msg = @@default_error_messages[:too_long], too_short_msg = @@default_error_messages[:too_short]) - for attr in [attributes].flatten - value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s] - add(attr, too_short_msg % range.begin) if value && value.length < range.begin - add(attr, too_long_msg % range.end) if value && value.length > range.end - end - end - - alias :add_on_boundry_breaking :add_on_boundary_breaking - deprecate :add_on_boundary_breaking => :validates_length_of, :add_on_boundry_breaking => :validates_length_of - # Returns true if the specified +attribute+ has errors associated with it. # # class Company < ActiveRecord::Base |