From 9bc75fd007d56d818b8620569410a20aa92c9fc5 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 6 Apr 2008 02:18:42 +0000 Subject: Remove duplicate code from associations. [Pratik] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9231 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../associations/has_many_association.rb | 41 ---------------------- 1 file changed, 41 deletions(-) (limited to 'activerecord/lib/active_record/associations/has_many_association.rb') diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 6cf10c2192..963a938485 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -1,11 +1,6 @@ module ActiveRecord module Associations class HasManyAssociation < AssociationCollection #:nodoc: - def initialize(owner, reflection) - super - construct_sql - end - # Count the number of associated records. All arguments are optional. def count(*args) if @reflection.options[:counter_sql] @@ -23,42 +18,6 @@ module ActiveRecord end end - def find(*args) - options = args.extract_options! - - # If using a custom finder_sql, scan the entire collection. - if @reflection.options[:finder_sql] - expects_array = args.first.kind_of?(Array) - ids = args.flatten.compact.uniq.map(&:to_i) - - if ids.size == 1 - id = ids.first - record = load_target.detect { |r| id == r.id } - expects_array ? [ record ] : record - else - load_target.select { |r| ids.include?(r.id) } - end - else - conditions = "#{@finder_sql}" - if sanitized_conditions = sanitize_sql(options[:conditions]) - conditions << " AND (#{sanitized_conditions})" - end - options[:conditions] = conditions - - if options[:order] && @reflection.options[:order] - options[:order] = "#{options[:order]}, #{@reflection.options[:order]}" - elsif @reflection.options[:order] - options[:order] = @reflection.options[:order] - end - - merge_options_from_reflection!(options) - - # Pass through args exactly as we received them. - args << options - @reflection.klass.find(*args) - end - end - protected def count_records count = if has_cached_counter? -- cgit v1.2.3