aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-06-27 20:13:17 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-06-27 20:32:17 +0900
commit442c15f1419ae60e4345866e5af59376a679e9d1 (patch)
tree993145931beba3aff0d463151af068e7cd3c183f /activerecord/lib/active_record/associations
parent23bcc6578e28355cc7258c744bcb26c0c80524ef (diff)
downloadrails-442c15f1419ae60e4345866e5af59376a679e9d1.tar.gz
rails-442c15f1419ae60e4345866e5af59376a679e9d1.tar.bz2
rails-442c15f1419ae60e4345866e5af59376a679e9d1.zip
Move building constraint to `join_scope` in `Reflection`
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb42
1 files changed, 3 insertions, 39 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index 70520b8e85..005410d598 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -34,18 +34,10 @@ module ActiveRecord
table = tables.shift
klass = reflection.klass
- join_keys = reflection.join_keys
- key = join_keys.key
- foreign_key = join_keys.foreign_key
+ join_scope = reflection.join_scope(table, foreign_table, foreign_klass)
- constraint = build_constraint(klass, table, key, foreign_table, foreign_key)
-
- rel = reflection.join_scope(table, foreign_klass)
-
- if rel.arel.constraints.any?
- binds += rel.bound_attributes
- constraint = constraint.and rel.arel.constraints
- end
+ binds.concat join_scope.bound_attributes
+ constraint = join_scope.arel.constraints
joins << table.create_join(table, table.create_on(constraint), join_type)
@@ -56,34 +48,6 @@ module ActiveRecord
JoinInformation.new joins, binds
end
- # Builds equality condition.
- #
- # Example:
- #
- # class Physician < ActiveRecord::Base
- # has_many :appointments
- # end
- #
- # If I execute `Physician.joins(:appointments).to_a` then
- # klass # => Physician
- # table # => #<Arel::Table @name="appointments" ...>
- # key # => physician_id
- # foreign_table # => #<Arel::Table @name="physicians" ...>
- # foreign_key # => id
- #
- def build_constraint(klass, table, key, foreign_table, foreign_key)
- constraint = table[key].eq(foreign_table[foreign_key])
-
- if klass.finder_needs_type_condition?
- constraint = table.create_and([
- constraint,
- klass.send(:type_condition, table)
- ])
- end
-
- constraint
- end
-
def table
tables.first
end