From db045dbbf60b53dbe013ef25554fd013baf88134 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 24 Nov 2004 01:04:44 +0000 Subject: Initial git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_record/deprecated_associations.rb | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 activerecord/lib/active_record/deprecated_associations.rb (limited to 'activerecord/lib/active_record/deprecated_associations.rb') diff --git a/activerecord/lib/active_record/deprecated_associations.rb b/activerecord/lib/active_record/deprecated_associations.rb new file mode 100644 index 0000000000..481b66bf0a --- /dev/null +++ b/activerecord/lib/active_record/deprecated_associations.rb @@ -0,0 +1,70 @@ +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) + #{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 + 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 + 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 + 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 + 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) + end + end_eval + end + + def deprecated_create_method(collection_name)# :nodoc: + module_eval <<-"end_eval", __FILE__, __LINE__ + def create_in_#{collection_name}(attributes = {}) + #{collection_name}.create(attributes) + end + end_eval + end + + def deprecated_build_method(collection_name)# :nodoc: + module_eval <<-"end_eval", __FILE__, __LINE__ + def build_to_#{collection_name}(attributes = {}) + #{collection_name}.build(attributes) + end + end_eval + end + end + end +end -- cgit v1.2.3