Permalink
Browse files

remove HABTM special cases from associations classes

  • Loading branch information...
1 parent 99185f0 commit 88c009377851912c60fd16ec4bfab3001ac2cf9f @tenderlove tenderlove committed Oct 2, 2013
View
12 activerecord/lib/active_record/associations/association_scope.rb
@@ -44,18 +44,6 @@ def add_constraints(scope)
chain.each_with_index do |reflection, i|
table, foreign_table = tables.shift, tables.first
- if reflection.source_macro == :has_and_belongs_to_many
- join_table = tables.shift
-
- scope = scope.joins(join(
- join_table,
- table[reflection.association_primary_key].
- eq(join_table[reflection.association_foreign_key])
- ))
-
- table, foreign_table = join_table, tables.first
- end
-
if reflection.source_macro == :belongs_to
if reflection.options[:polymorphic]
key = reflection.association_primary_key(self.klass)
View
2 activerecord/lib/active_record/associations/join_dependency.rb
@@ -216,7 +216,7 @@ def construct_association(record, join_part, row)
else
association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
case macro
- when :has_many, :has_and_belongs_to_many
+ when :has_many
other = record.association(join_part.reflection.name)
other.loaded!
other.target.push(association) if association
View
11 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -83,17 +83,6 @@ def join_constraints
when :belongs_to
key = reflection.association_primary_key
foreign_key = reflection.foreign_key
- when :has_and_belongs_to_many
- # Join the join table first...
- joins << join(
- table,
- table[reflection.foreign_key].
- eq(foreign_table[reflection.active_record_primary_key]))
-
- foreign_table, table = table, tables.shift
-
- key = reflection.association_primary_key
- foreign_key = reflection.association_foreign_key
else
key = reflection.foreign_key
foreign_key = reflection.active_record_primary_key
View
7 activerecord/lib/active_record/associations/join_helper.rb
@@ -16,13 +16,6 @@ def construct_tables
table_name_for(reflection),
table_alias_for(reflection, reflection != self.reflection)
)
-
- if reflection.source_macro == :has_and_belongs_to_many
- tables << alias_tracker.aliased_table_for(
- reflection.source_reflection.join_table,
- table_alias_for(reflection, true)
- )
- end
end
tables
end

0 comments on commit 88c0093

Please sign in to comment.