Changeset 7402
- Timestamp:
- 09/03/07 00:17:09 (2 years ago)
- Files:
-
- trunk/activerecord/lib/active_record/associations.rb (modified) (13 diffs)
- trunk/activerecord/lib/active_record/deprecated_associations.rb (deleted)
- trunk/activerecord/lib/active_record/validations.rb (modified) (1 diff)
- trunk/activerecord/test/associations_test.rb (modified) (3 diffs)
- trunk/activerecord/test/deprecated_associations_test.rb (deleted)
- trunk/activerecord/test/mixin_test.rb (modified) (2 diffs)
- trunk/activerecord/test/reflection_test.rb (modified) (1 diff)
- trunk/activerecord/test/validations_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/associations.rb
r7368 r7402 7 7 require 'active_record/associations/has_many_through_association' 8 8 require 'active_record/associations/has_and_belongs_to_many_association' 9 require 'active_record/deprecated_associations'10 9 11 10 module ActiveRecord … … 626 625 # objects are deleted *without* calling their destroy method. If set to <tt>:nullify</tt> all associated 627 626 # objects' foreign keys are set to +NULL+ *without* calling their save callbacks. 628 # NOTE: <tt>:dependent => true</tt> is deprecated and has been replaced with <tt>:dependent => :destroy</tt>.629 627 # May not be set if <tt>:exclusively_dependent</tt> is also set. 630 # * <tt>:exclusively_dependent</tt> - Deprecated; equivalent to <tt>:dependent => :delete_all</tt>. If set to +true+ all631 # the associated objects are deleted in one SQL statement without having their632 # +before_destroy+ callback run. This should only be used on associations that depend solely on this class and don't need to do any633 # clean-up in +before_destroy+. The upside is that it's much faster, especially if there's a +counter_cache+ involved.634 # May not be set if <tt>:dependent</tt> is also set.635 628 # * <tt>:finder_sql</tt> - specify a complete SQL statement to fetch the association. This is a good way to go for complex 636 629 # associations that depend on multiple tables. Note: When this option is used, +find_in_collection+ is _not_ added. … … 681 674 collection_accessor_methods(reflection, HasManyAssociation) 682 675 end 683 684 add_deprecated_api_for_has_many(reflection.name)685 676 end 686 677 … … 748 739 749 740 configure_dependency_for_has_one(reflection) 750 751 # deprecated api752 deprecated_has_association_method(reflection.name)753 deprecated_association_comparison_method(reflection.name, reflection.class_name)754 741 end 755 742 … … 839 826 EOF 840 827 end 841 842 # deprecated api843 deprecated_has_association_method(reflection.name)844 deprecated_association_comparison_method(reflection.name, reflection.class_name)845 828 end 846 829 … … 885 868 # * <tt>collection<<(object, ...)</tt> - adds one or more objects to the collection by creating associations in the join table 886 869 # (<tt>collection.push</tt> and <tt>collection.concat</tt> are aliases to this method). 887 # * <tt>collection.push_with_attributes(object, join_attributes)</tt> - adds one to the collection by creating an association in the join table that888 # 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 additional889 # attributes on the join, which will be injected into the associated objects when they are retrieved through the collection.890 # (<tt>collection.concat_with_attributes</tt> is an alias to this method). This method is now deprecated.891 870 # * <tt>collection.delete(object, ...)</tt> - removes one or more objects from the collection by removing their associations from the join table. 892 871 # This does not destroy the objects. … … 974 953 975 954 add_association_callbacks(reflection.name, options) 976 977 # deprecated api978 deprecated_collection_count_method(reflection.name)979 deprecated_add_association_relation(reflection.name)980 deprecated_remove_association_relation(reflection.name)981 deprecated_has_collection_method(reflection.name)982 955 end 983 956 … … 1142 1115 1143 1116 def configure_dependency_for_has_many(reflection) 1144 if reflection.options[:dependent] == true1145 ::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)1146 end1147 1148 if reflection.options[:dependent] && reflection.options[:exclusively_dependent]1149 raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options. You may specify one or the other.'1150 end1151 1152 if reflection.options[:exclusively_dependent]1153 reflection.options[:dependent] = :delete_all1154 ::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)1155 end1156 1157 1117 # See HasManyAssociation#delete_records. Dependent associations 1158 1118 # delete children, otherwise foreign key is set to NULL. … … 1166 1126 1167 1127 case reflection.options[:dependent] 1168 when :destroy , true1128 when :destroy 1169 1129 module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'" 1170 1130 when :delete_all … … 1172 1132 when :nullify 1173 1133 module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL), %(#{dependent_conditions})) }" 1174 when nil , false1134 when nil 1175 1135 # pass 1176 1136 else … … 1181 1141 def configure_dependency_for_has_one(reflection) 1182 1142 case reflection.options[:dependent] 1183 when :destroy , true1143 when :destroy 1184 1144 module_eval "before_destroy '#{reflection.name}.destroy unless #{reflection.name}.nil?'" 1185 1145 when :delete … … 1187 1147 when :nullify 1188 1148 module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil) unless #{reflection.name}.nil?'" 1189 when nil , false1149 when nil 1190 1150 # pass 1191 1151 else … … 1193 1153 end 1194 1154 end 1195 1196 1197 def add_deprecated_api_for_has_many(association_name)1198 deprecated_collection_count_method(association_name)1199 deprecated_add_association_relation(association_name)1200 deprecated_remove_association_relation(association_name)1201 deprecated_has_collection_method(association_name)1202 deprecated_find_in_collection_method(association_name)1203 deprecated_collection_create_method(association_name)1204 deprecated_collection_build_method(association_name)1205 end1206 1155 1207 1156 def create_has_many_reflection(association_id, options, &extension) 1208 1157 options.assert_valid_keys( 1209 1158 :class_name, :table_name, :foreign_key, 1210 : exclusively_dependent, :dependent,1159 :dependent, 1211 1160 :select, :conditions, :include, :order, :group, :limit, :offset, 1212 1161 :as, :through, :source, :source_type, trunk/activerecord/lib/active_record/validations.rb
r7365 r7402 83 83 end 84 84 end 85 86 # Will add an error message to each of the attributes in +attributes+ that has a length outside of the passed boundary +range+.87 # If the length is above the boundary, the too_long_msg message will be used. If below, the too_short_msg.88 def add_on_boundary_breaking(attributes, range, too_long_msg = @@default_error_messages[:too_long], too_short_msg = @@default_error_messages[:too_short])89 for attr in [attributes].flatten90 value = @base.respond_to?(attr.to_s) ? @base.send(attr.to_s) : @base[attr.to_s]91 add(attr, too_short_msg % range.begin) if value && value.length < range.begin92 add(attr, too_long_msg % range.end) if value && value.length > range.end93 end94 end95 96 alias :add_on_boundry_breaking :add_on_boundary_breaking97 deprecate :add_on_boundary_breaking => :validates_length_of, :add_on_boundry_breaking => :validates_length_of98 85 99 86 # Returns true if the specified +attribute+ has errors associated with it. trunk/activerecord/test/associations_test.rb
r7315 r7402 31 31 firm.clients.each {|c|} # forcing to load all clients 32 32 assert firm.clients.empty?, "New firm shouldn't have client objects" 33 assert_deprecated do34 assert !firm.has_clients?, "New firm shouldn't have clients"35 end36 33 assert_equal 0, firm.clients.size, "New firm should have 0 clients" 37 34 … … 40 37 41 38 assert firm.clients.empty?, "New firm should have cached no client objects" 42 assert_deprecated do43 assert !firm.has_clients?, "New firm should have cached a no-clients response"44 end45 39 assert_equal 0, firm.clients.size, "New firm should have cached 0 clients count" 46 40 … … 214 208 assert_equal num_accounts - 1, Account.count 215 209 assert_equal [account_id], Account.destroyed_account_ids[firm.id] 216 end217 218 def test_deprecated_exclusive_dependence219 assert_deprecated(/:exclusively_dependent.*:dependent => :delete_all/) do220 Firm.has_many :deprecated_exclusively_dependent_clients, :class_name => 'Client', :exclusively_dependent => true221 end222 210 end 223 211 trunk/activerecord/test/mixin_test.rb
r7081 r7402 184 184 fixtures :mixins 185 185 186 def test_has_child187 assert_deprecated 'has_children?' do188 assert_equal true, mixins(:tree_1).has_children?189 assert_equal true, mixins(:tree_2).has_children?190 assert_equal false, mixins(:tree_3).has_children?191 assert_equal false, mixins(:tree_4).has_children?192 end193 end194 195 186 def test_children 196 187 assert_equal mixins(:tree_1).children, mixins(:tree_2, :tree_4) … … 198 189 assert_equal mixins(:tree_3).children, [] 199 190 assert_equal mixins(:tree_4).children, [] 200 end201 202 def test_has_parent203 assert_deprecated 'has_parent?' do204 assert_equal false, mixins(:tree_1).has_parent?205 assert_equal true, mixins(:tree_2).has_parent?206 assert_equal true, mixins(:tree_3).has_parent?207 assert_equal true, mixins(:tree_4).has_parent?208 end209 191 end 210 192 trunk/activerecord/test/reflection_test.rb
r7188 r7402 160 160 161 161 def test_reflection_of_all_associations 162 assert_equal 1 7, Firm.reflect_on_all_associations.size163 assert_equal 1 5, Firm.reflect_on_all_associations(:has_many).size162 assert_equal 16, Firm.reflect_on_all_associations.size 163 assert_equal 14, Firm.reflect_on_all_associations(:has_many).size 164 164 assert_equal 2, Firm.reflect_on_all_associations(:has_one).size 165 165 assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size trunk/activerecord/test/validations_test.rb
r7365 r7402 652 652 assert_equal 'tu est trops petit hombre 10', t.errors['title'] 653 653 end 654 655 def test_add_on_boundary_breaking_is_deprecated656 t = Topic.new('title' => 'noreplies', 'content' => 'whatever')657 class << t658 def validate659 errors.add_on_boundary_breaking('title', 1..6)660 end661 end662 assert_deprecated 'add_on_boundary_breaking' do663 assert !t.valid?664 end665 end666 654 667 655 def test_validates_size_of_association