Skip to content

Commit 4ac6592

Browse files
author
Keith Gabryelski
committed
Merge pull request #32 from eslavich/destroy-on-partitioned-table-fails
Create a new relation with the partition's Arel::Table and use that to d...
2 parents 35753ad + 87f24b4 commit 4ac6592

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/monkey_patch_activerecord.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,26 @@ module Persistence
1717
# that no changes should be made (since they can't be persisted).
1818
def destroy
1919
destroy_associations
20-
20+
2121
if persisted?
2222
IdentityMap.remove(self) if IdentityMap.enabled?
2323
pk = self.class.primary_key
2424
column = self.class.columns_hash[pk]
2525
substitute = connection.substitute_at(column, 0)
26-
27-
using_arel_table = self.respond_to?(:dynamic_arel_table) ? dynamic_arel_table() : self.class.arel_table
28-
relation = self.class.unscoped.where(
29-
using_arel_table[pk].eq(substitute))
30-
26+
27+
if self.class.respond_to?(:dynamic_arel_table)
28+
using_arel_table = dynamic_arel_table()
29+
relation = ActiveRecord::Relation.new(self.class, using_arel_table).
30+
where(using_arel_table[pk].eq(substitute))
31+
else
32+
using_arel_table = self.class.arel_table
33+
relation = self.class.unscoped.where(using_arel_table[pk].eq(substitute))
34+
end
35+
3136
relation.bind_values = [[column, id]]
3237
relation.delete_all
3338
end
34-
39+
3540
@destroyed = true
3641
freeze
3742
end

0 commit comments

Comments
 (0)