Skip to content
This repository
Browse code

Remove find_with_associations and related code from associations now …

…that Relation handles that stuff
  • Loading branch information...
commit 42553a98eaa05c703de52147c870e4dd9a3d50ba 1 parent 6e62e89
Pratik lifo authored
67 activerecord/lib/active_record/associations.rb
@@ -1463,13 +1463,6 @@ def add_touch_callbacks(reflection, touch_attribute)
1463 1463 after_destroy(method_name)
1464 1464 end
1465 1465
1466   - def find_with_associations(options, join_dependency)
1467   - rows = select_all_rows(options, join_dependency)
1468   - join_dependency.instantiate(rows)
1469   - rescue ThrowResult
1470   - []
1471   - end
1472   -
1473 1466 # Creates before_destroy callback methods that nullify, delete or destroy
1474 1467 # has_many associated objects, according to the defined :dependent rule.
1475 1468 #
@@ -1693,66 +1686,6 @@ def create_has_and_belongs_to_many_reflection(association_id, options, &extensio
1693 1686 reflection
1694 1687 end
1695 1688
1696   - def select_all_rows(options, join_dependency)
1697   - connection.select_all(
1698   - construct_finder_sql_with_included_associations(options, join_dependency),
1699   - "#{name} Load Including Associations"
1700   - )
1701   - end
1702   -
1703   - def construct_finder_arel_with_included_associations(options, join_dependency)
1704   - relation = scoped
1705   -
1706   - for association in join_dependency.join_associations
1707   - relation = association.join_relation(relation)
1708   - end
1709   -
1710   - relation = relation.apply_finder_options(options).select(column_aliases(join_dependency))
1711   -
1712   - if !using_limitable_reflections?(join_dependency.reflections) && relation.limit_value
1713   - relation = relation.where(construct_arel_limited_ids_condition(options, join_dependency))
1714   - end
1715   -
1716   - relation = relation.except(:limit, :offset) unless using_limitable_reflections?(join_dependency.reflections)
1717   -
1718   - relation
1719   - end
1720   -
1721   - def construct_finder_sql_with_included_associations(options, join_dependency)
1722   - construct_finder_arel_with_included_associations(options, join_dependency).to_sql
1723   - end
1724   -
1725   - def construct_arel_limited_ids_condition(options, join_dependency)
1726   - if (ids_array = select_limited_ids_array(options, join_dependency)).empty?
1727   - raise ThrowResult
1728   - else
1729   - Arel::Predicates::In.new(
1730   - Arel::SqlLiteral.new("#{connection.quote_table_name table_name}.#{primary_key}"),
1731   - ids_array
1732   - )
1733   - end
1734   - end
1735   -
1736   - def select_limited_ids_array(options, join_dependency)
1737   - connection.select_all(
1738   - construct_finder_sql_for_association_limiting(options, join_dependency),
1739   - "#{name} Load IDs For Limited Eager Loading"
1740   - ).collect { |row| row[primary_key] }
1741   - end
1742   -
1743   - def construct_finder_sql_for_association_limiting(options, join_dependency)
1744   - relation = scoped
1745   -
1746   - for association in join_dependency.join_associations
1747   - relation = association.join_relation(relation)
1748   - end
1749   -
1750   - relation = relation.apply_finder_options(options).except(:select)
1751   - relation = relation.select(connection.distinct("#{connection.quote_table_name table_name}.#{primary_key}", relation.order_values.join(", ")))
1752   -
1753   - relation.to_sql
1754   - end
1755   -
1756 1689 def using_limitable_reflections?(reflections)
1757 1690 reflections.collect(&:collection?).length.zero?
1758 1691 end
15 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -732,21 +732,6 @@ def test_assign_ids_ignoring_blanks
732 732 assert_equal [projects(:active_record), projects(:action_controller)].map(&:id).sort, developer.project_ids.sort
733 733 end
734 734
735   - def test_select_limited_ids_array
736   - # Set timestamps
737   - Developer.transaction do
738   - Developer.find(:all, :order => 'id').each_with_index do |record, i|
739   - record.update_attributes(:created_at => 5.years.ago + (i * 5.minutes))
740   - end
741   - end
742   -
743   - join_base = ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase.new(Project)
744   - join_dep = ActiveRecord::Associations::ClassMethods::JoinDependency.new(join_base, :developers, nil)
745   - projects = Project.send(:select_limited_ids_array, {:order => 'developers.created_at'}, join_dep)
746   - assert !projects.include?("'"), projects
747   - assert_equal ["1", "2"], projects.sort
748   - end
749   -
750 735 def test_scoped_find_on_through_association_doesnt_return_read_only_records
751 736 tag = Post.find(1).tags.find_by_name("General")
752 737

0 comments on commit 42553a9

Please sign in to comment.
Something went wrong with that request. Please try again.