提交 88c00937 编写于 作者: A Aaron Patterson

remove HABTM special cases from associations classes

上级 99185f00
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册