diff options
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index aceb83044b..d748500340 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -2148,22 +2148,23 @@ module ActiveRecord end def relation + aliased = Arel::Table.new(table_name, :as => @aliased_table_name) + if reflection.macro == :has_and_belongs_to_many - [Arel::Table.new(table_alias_for(options[:join_table], aliased_join_table_name)), Arel::Table.new(table_name_and_alias)] + [Arel::Table.new(options[:join_table], :as => aliased_join_table_name), aliased] elsif reflection.options[:through] - [Arel::Table.new(table_alias_for(through_reflection.klass.table_name, aliased_join_table_name)), Arel::Table.new(table_name_and_alias)] + [Arel::Table.new(through_reflection.klass.table_name, :as => aliased_join_table_name), aliased] else - Arel::Table.new(table_name_and_alias) + aliased end end def join_relation(joining_relation, join = nil) if (relations = relation).is_a?(Array) - joining_relation. - joins(relations.first, Arel::OuterJoin).on(association_join.first). - joins(relations.last, Arel::OuterJoin).on(association_join.last) + joining_relation.joins(Relation::JoinOperation.new(relations.first, Arel::OuterJoin, association_join.first)). + joins(Relation::JoinOperation.new(relations.last, Arel::OuterJoin, association_join.last)) else - joining_relation.joins(relations, Arel::OuterJoin).on(association_join) + joining_relation.joins(Relation::JoinOperation.new(relations, Arel::OuterJoin, association_join)) end end |