diff options
Diffstat (limited to 'lib/active_relation/relations/join.rb')
-rw-r--r-- | lib/active_relation/relations/join.rb | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/lib/active_relation/relations/join.rb b/lib/active_relation/relations/join.rb index 4c4f2e66a2..c61680fd55 100644 --- a/lib/active_relation/relations/join.rb +++ b/lib/active_relation/relations/join.rb @@ -20,20 +20,22 @@ module ActiveRelation def attributes [ - relation1.aggregation?? relation1.attributes.collect(&:to_attribute) : relation1.attributes, - relation2.aggregation?? relation2.attributes.collect(&:to_attribute) : relation2.attributes, + relation1.attributes.collect(&:to_attribute), + relation2.attributes.collect(&:to_attribute), ].flatten.collect { |a| a.bind(self) } end def prefix_for(attribute) - (relation1[attribute] && relation1.aliased_prefix_for(attribute)) || - (relation2[attribute] && relation2.aliased_prefix_for(attribute)) + relation1.aliased_prefix_for(attribute) or + relation2.aliased_prefix_for(attribute) end alias_method :aliased_prefix_for, :prefix_for protected def joins - [relation1.joins, relation2.joins, join].compact.join(" ") + right_table_sql = relation2.aggregation?? relation2.to_sql(Sql::Aggregation.new) : relation2.send(:table_sql) + this_join = [join_sql, right_table_sql, "ON", predicates.collect { |p| p.bind(self).to_sql(Sql::Predicate.new) }.join(' AND ')].join(" ") + [relation1.joins, relation2.joins, this_join].compact.join(" ") end def selects @@ -46,14 +48,5 @@ module ActiveRelation def table_sql relation1.aggregation?? relation1.to_sql(Sql::Aggregation.new) : relation1.send(:table_sql) end - - private - def join - [join_sql, right_table_sql, "ON", predicates.collect { |p| p.bind(self).to_sql(Sql::Predicate.new) }.join(' AND ')].join(" ") - end - - def right_table_sql - relation2.aggregation?? relation2.to_sql(Sql::Aggregation.new) : relation2.send(:table_sql) - end end end
\ No newline at end of file |