aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-11 04:28:28 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-01-11 04:28:28 +0900
commit412db710dfa6ed84654068576b1841966d7f89b2 (patch)
treeedd43195cf3ccb3f9c9d87a552fdc13f7e3242af /activerecord/lib/active_record/relation/finder_methods.rb
parentb4f64cb1595f2abd3d7e47805273f4f029718829 (diff)
downloadrails-412db710dfa6ed84654068576b1841966d7f89b2.tar.gz
rails-412db710dfa6ed84654068576b1841966d7f89b2.tar.bz2
rails-412db710dfa6ed84654068576b1841966d7f89b2.zip
Use `apply_join_dependency` instead of meaningless named `find_with_associations`
`find_with_associations` is meaningless name in this point since it just contain `construct_join_dependency` and `apply_join_dependency`, does not contain finding anything. If `apply_join_dependency` returns `relation` and `join_dependency` then `find_with_associations` is no longer needed.
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb35
1 files changed, 11 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 12ac89f5ad..98992caa0c 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -358,24 +358,6 @@ module ActiveRecord
offset_value || 0
end
- def find_with_associations
- # NOTE: the JoinDependency constructed here needs to know about
- # any joins already present in `self`, so pass them in
- #
- # failing to do so means that in cases like activerecord/test/cases/associations/inner_join_association_test.rb:136
- # incorrect SQL is generated. In that case, the join dependency for
- # SpecialCategorizations is constructed without knowledge of the
- # preexisting join in joins_values to categorizations (by way of
- # the `has_many :through` for categories).
- #
- join_dependency = construct_join_dependency
-
- relation = apply_join_dependency(join_dependency)
- relation._select!(join_dependency.aliases.columns)
-
- yield relation, join_dependency
- end
-
def construct_relation_for_exists(conditions)
relation = except(:select, :distinct, :order)._select!(ONE_AS_ONE).limit!(1)
@@ -396,18 +378,23 @@ module ActiveRecord
)
end
- def apply_join_dependency(join_dependency = nil, eager_loading: true)
- join_dependency ||= construct_join_dependency(eager_loading: eager_loading)
+ def apply_join_dependency(eager_loading: true)
+ join_dependency = construct_join_dependency(eager_loading: eager_loading)
relation = except(:includes, :eager_load, :preload).joins!(join_dependency)
- if !eager_loading || using_limitable_reflections?(join_dependency.reflections)
- relation
- else
+ if eager_loading && !using_limitable_reflections?(join_dependency.reflections)
if has_limit_or_offset?
limited_ids = limited_ids_for(relation)
limited_ids.empty? ? relation.none! : relation.where!(primary_key => limited_ids)
end
- relation.except(:limit, :offset)
+ relation.limit_value = relation.offset_value = nil
+ end
+
+ if block_given?
+ relation._select!(join_dependency.aliases.columns)
+ yield relation, join_dependency
+ else
+ relation
end
end