From 0cfb1de4583b5926bbb10de39d80d8537a7e6482 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 9 Oct 2013 15:25:19 -0700 Subject: [PATCH] add some convenient methods for avoiding array allocations --- .../lib/active_record/associations/join_dependency.rb | 6 +++--- .../active_record/associations/join_dependency/join_part.rb | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 4d1f7a1041..d0c920ce4c 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -76,17 +76,17 @@ def graft(*associations) end def reflections - join_root.drop(1).map(&:reflection) + join_root.drop(1).map!(&:reflection) end def join_relation(relation) - join_root.drop(1).inject(relation) do |rel,association| + join_root.inject(relation) do |rel,association| association.join_relation(rel) end end def join_constraints - join_root.drop(1).flat_map(&:join_constraints) + join_root.flat_map(&:join_constraints) end def columns diff --git a/activerecord/lib/active_record/associations/join_dependency/join_part.rb b/activerecord/lib/active_record/associations/join_dependency/join_part.rb index 27304acceb..d536eaf613 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb @@ -29,6 +29,9 @@ def initialize(base_klass, parent) @children = [] end + def join_constraints; []; end + def join_relation(rel); rel; end + def name reflection.name end -- GitLab