aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-20 01:19:53 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-20 01:20:20 +0530
commit42553a98eaa05c703de52147c870e4dd9a3d50ba (patch)
tree232f2e5a3e75fac725d92ce9f276f9ea812d6567 /activerecord
parent6e62e89737c991de712a13b67a282ce599710ec9 (diff)
downloadrails-42553a98eaa05c703de52147c870e4dd9a3d50ba.tar.gz
rails-42553a98eaa05c703de52147c870e4dd9a3d50ba.tar.bz2
rails-42553a98eaa05c703de52147c870e4dd9a3d50ba.zip
Remove find_with_associations and related code from associations now that Relation handles that stuff
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb67
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb15
2 files changed, 0 insertions, 82 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index ebf1a41e85..57785b4c93 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1463,13 +1463,6 @@ module ActiveRecord
after_destroy(method_name)
end
- def find_with_associations(options, join_dependency)
- rows = select_all_rows(options, join_dependency)
- join_dependency.instantiate(rows)
- rescue ThrowResult
- []
- end
-
# Creates before_destroy callback methods that nullify, delete or destroy
# has_many associated objects, according to the defined :dependent rule.
#
@@ -1693,66 +1686,6 @@ module ActiveRecord
reflection
end
- def select_all_rows(options, join_dependency)
- connection.select_all(
- construct_finder_sql_with_included_associations(options, join_dependency),
- "#{name} Load Including Associations"
- )
- end
-
- def construct_finder_arel_with_included_associations(options, join_dependency)
- relation = scoped
-
- for association in join_dependency.join_associations
- relation = association.join_relation(relation)
- end
-
- relation = relation.apply_finder_options(options).select(column_aliases(join_dependency))
-
- if !using_limitable_reflections?(join_dependency.reflections) && relation.limit_value
- relation = relation.where(construct_arel_limited_ids_condition(options, join_dependency))
- end
-
- relation = relation.except(:limit, :offset) unless using_limitable_reflections?(join_dependency.reflections)
-
- relation
- end
-
- def construct_finder_sql_with_included_associations(options, join_dependency)
- construct_finder_arel_with_included_associations(options, join_dependency).to_sql
- end
-
- def construct_arel_limited_ids_condition(options, join_dependency)
- if (ids_array = select_limited_ids_array(options, join_dependency)).empty?
- raise ThrowResult
- else
- Arel::Predicates::In.new(
- Arel::SqlLiteral.new("#{connection.quote_table_name table_name}.#{primary_key}"),
- ids_array
- )
- end
- end
-
- def select_limited_ids_array(options, join_dependency)
- connection.select_all(
- construct_finder_sql_for_association_limiting(options, join_dependency),
- "#{name} Load IDs For Limited Eager Loading"
- ).collect { |row| row[primary_key] }
- end
-
- def construct_finder_sql_for_association_limiting(options, join_dependency)
- relation = scoped
-
- for association in join_dependency.join_associations
- relation = association.join_relation(relation)
- end
-
- relation = relation.apply_finder_options(options).except(:select)
- relation = relation.select(connection.distinct("#{connection.quote_table_name table_name}.#{primary_key}", relation.order_values.join(", ")))
-
- relation.to_sql
- end
-
def using_limitable_reflections?(reflections)
reflections.collect(&:collection?).length.zero?
end
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 1bce45865f..004d0156e1 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -732,21 +732,6 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal [projects(:active_record), projects(:action_controller)].map(&:id).sort, developer.project_ids.sort
end
- def test_select_limited_ids_array
- # Set timestamps
- Developer.transaction do
- Developer.find(:all, :order => 'id').each_with_index do |record, i|
- record.update_attributes(:created_at => 5.years.ago + (i * 5.minutes))
- end
- end
-
- join_base = ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase.new(Project)
- join_dep = ActiveRecord::Associations::ClassMethods::JoinDependency.new(join_base, :developers, nil)
- projects = Project.send(:select_limited_ids_array, {:order => 'developers.created_at'}, join_dep)
- assert !projects.include?("'"), projects
- assert_equal ["1", "2"], projects.sort
- end
-
def test_scoped_find_on_through_association_doesnt_return_read_only_records
tag = Post.find(1).tags.find_by_name("General")