aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-09-15 07:02:05 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-09-15 07:02:05 +0000
commit3f1acf49bd4cfa902388f000ca96c848c3666017 (patch)
treeaf197c1f4ea786e76da1f0679225572ea1953a58 /activerecord/lib
parentd0c000ab9e90be4896744cb6ec107dffa573f2dd (diff)
downloadrails-3f1acf49bd4cfa902388f000ca96c848c3666017.tar.gz
rails-3f1acf49bd4cfa902388f000ca96c848c3666017.tar.bz2
rails-3f1acf49bd4cfa902388f000ca96c848c3666017.zip
Deprecation tests. Remove warnings for dynamic finders and for the foo_count ethod if it's also an attribute.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5116 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/acts/tree.rb24
-rwxr-xr-xactiverecord/lib/active_record/associations.rb10
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb2
-rwxr-xr-xactiverecord/lib/active_record/base.rb10
-rw-r--r--activerecord/lib/active_record/deprecated_associations.rb34
5 files changed, 51 insertions, 29 deletions
diff --git a/activerecord/lib/active_record/acts/tree.rb b/activerecord/lib/active_record/acts/tree.rb
index b8654ce4e6..44432d4741 100644
--- a/activerecord/lib/active_record/acts/tree.rb
+++ b/activerecord/lib/active_record/acts/tree.rb
@@ -2,19 +2,19 @@ module ActiveRecord
module Acts #:nodoc:
module Tree #:nodoc:
def self.included(base)
- base.extend(ClassMethods)
- end
+ base.extend(ClassMethods)
+ end
- # Specify this act if you want to model a tree structure by providing a parent association and a children
+ # Specify this act if you want to model a tree structure by providing a parent association and a children
# association. This act requires that you have a foreign key column, which by default is called parent_id.
- #
+ #
# class Category < ActiveRecord::Base
# acts_as_tree :order => "name"
# end
- #
- # Example :
+ #
+ # Example:
# root
- # \_ child1
+ # \_ child1
# \_ subchild1
# \_ subchild2
#
@@ -27,7 +27,7 @@ module ActiveRecord
# root.children # => [child1]
# root.children.first.children.first # => subchild1
#
- # In addition to the parent and children associations, the following instance methods are added to the class
+ # In addition to the parent and children associations, the following instance methods are added to the class
# after specifying the act:
# * siblings : Returns all the children of the parent, excluding the current node ([ subchild2 ] when called from subchild1)
# * self_and_siblings : Returns all the children of the parent, including the current node ([ subchild1, subchild2 ] when called from subchild1)
@@ -48,7 +48,7 @@ module ActiveRecord
class_eval <<-EOV
include ActiveRecord::Acts::Tree::InstanceMethods
-
+
def self.roots
find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
end
@@ -66,13 +66,13 @@ module ActiveRecord
# subchild1.ancestors # => [child1, root]
def ancestors
node, nodes = self, []
- nodes << node = node.parent until not node.has_parent?
+ nodes << node = node.parent while node.parent
nodes
end
def root
node = self
- node = node.parent until not node.has_parent?
+ node = node.parent while node.parent
node
end
@@ -81,7 +81,7 @@ module ActiveRecord
end
def self_and_siblings
- has_parent? ? parent.children : self.class.roots
+ parent ? parent.children : self.class.roots
end
end
end
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index e2dca89d49..60f0a137b0 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -991,6 +991,10 @@ 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
@@ -1010,7 +1014,7 @@ module ActiveRecord
end
case reflection.options[:dependent]
- when :destroy, true
+ when :destroy, true
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})) }"
@@ -1019,10 +1023,10 @@ module ActiveRecord
when nil, false
# pass
else
- raise ArgumentError, 'The :dependent option expects either :destroy, :delete_all, or :nullify'
+ raise ArgumentError, 'The :dependent option expects either :destroy, :delete_all, or :nullify'
end
end
-
+
def configure_dependency_for_has_one(reflection)
case reflection.options[:dependent]
when :destroy, true
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index d3fdcbe02f..226698611c 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -31,11 +31,13 @@ module ActiveRecord
@reflection.klass.find_all(conditions, orderings, limit, joins)
end
end
+ deprecate :find_all
# DEPRECATED. Find the first associated record. All arguments are optional.
def find_first(conditions = nil, orderings = nil)
find_all(conditions, orderings, 1).first
end
+ deprecate :find_first
# Count the number of associated records. All arguments are optional.
def count(*args)
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index e9c9212560..43f631ef6c 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1198,7 +1198,7 @@ module ActiveRecord #:nodoc:
when nil
options = { :conditions => conditions }
set_readonly_option!(options)
- send(finder, options)
+ ActiveSupport::Deprecation.silence { send(finder, options) }
when Hash
finder_options = extra_options.merge(:conditions => conditions)
@@ -1207,14 +1207,16 @@ module ActiveRecord #:nodoc:
if extra_options[:conditions]
with_scope(:find => { :conditions => extra_options[:conditions] }) do
- send(finder, finder_options)
+ ActiveSupport::Deprecation.silence { send(finder, finder_options) }
end
else
- send(finder, finder_options)
+ ActiveSupport::Deprecation.silence { send(finder, finder_options) }
end
else
- send(deprecated_finder, conditions, *arguments[attribute_names.length..-1]) # deprecated API
+ ActiveSupport::Deprecation.silence do
+ send(deprecated_finder, conditions, *arguments[attribute_names.length..-1])
+ end
end
elsif match = /find_or_(initialize|create)_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
instantiator = determine_instantiator(match)
diff --git a/activerecord/lib/active_record/deprecated_associations.rb b/activerecord/lib/active_record/deprecated_associations.rb
index 077ac1de3b..4a0918c824 100644
--- a/activerecord/lib/active_record/deprecated_associations.rb
+++ b/activerecord/lib/active_record/deprecated_associations.rb
@@ -4,65 +4,77 @@ module ActiveRecord
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}
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}
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}?
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}
end_eval
end
-
+
def deprecated_find_all_in_collection_method(collection_name)# :nodoc:
module_eval <<-"end_eval", __FILE__, __LINE__
def find_all_in_#{collection_name}(runtime_conditions = nil, orderings = nil, limit = nil, joins = nil)
- #{collection_name}.find_all(runtime_conditions, orderings, limit, joins)
+ ActiveSupport::Deprecation.silence do
+ #{collection_name}.find_all(runtime_conditions, orderings, limit, joins)
+ end
end
+ deprecate :find_all_in_#{collection_name}
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}
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}
end_eval
end
@@ -75,16 +87,18 @@ module ActiveRecord
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}?
end_eval
- end
+ end
end
end
end