Use Arel::Table instead of ActiveRecord::Relation from HABTM and has_many#delete_records
This commit is contained in:
parent
fc94c03c1d
commit
5971842d2d
@ -44,7 +44,7 @@ def insert_record(record, force = true, validate = true)
|
||||
if @reflection.options[:insert_sql]
|
||||
@owner.connection.insert(interpolate_sql(@reflection.options[:insert_sql], record))
|
||||
else
|
||||
relation = arel_table(@reflection.options[:join_table])
|
||||
relation = Arel::Table.new(@reflection.options[:join_table])
|
||||
attributes = columns.inject({}) do |attrs, column|
|
||||
case column.name.to_s
|
||||
when @reflection.primary_key_name.to_s
|
||||
@ -70,10 +70,10 @@ def delete_records(records)
|
||||
if sql = @reflection.options[:delete_sql]
|
||||
records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) }
|
||||
else
|
||||
relation = arel_table(@reflection.options[:join_table])
|
||||
relation = Arel::Table.new(@reflection.options[:join_table])
|
||||
relation.where(relation[@reflection.primary_key_name].eq(@owner.id).
|
||||
and(Arel::Predicates::In.new(relation[@reflection.association_foreign_key], records.map(&:id)))
|
||||
).delete_all
|
||||
).delete
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -69,7 +69,7 @@ def delete_records(records)
|
||||
when :delete_all
|
||||
@reflection.klass.delete(records.map { |record| record.id })
|
||||
else
|
||||
relation = arel_table(@reflection.table_name)
|
||||
relation = Arel::Table.new(@reflection.table_name)
|
||||
relation.where(relation[@reflection.primary_key_name].eq(@owner.id).
|
||||
and(Arel::Predicates::In.new(relation[@reflection.klass.primary_key], records.map(&:id)))
|
||||
).update(relation[@reflection.primary_key_name] => nil)
|
||||
|
Loading…
Reference in New Issue
Block a user