提交 42553a98 编写于 作者: P Pratik Naik

Remove find_with_associations and related code from associations now that...

Remove find_with_associations and related code from associations now that Relation handles that stuff
上级 6e62e897
......@@ -1463,13 +1463,6 @@ def add_touch_callbacks(reflection, touch_attribute)
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 @@ def create_has_and_belongs_to_many_reflection(association_id, options, &extensio
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
......
......@@ -732,21 +732,6 @@ def test_assign_ids_ignoring_blanks
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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册