diff --git a/app/models/mixins/purging_mixin.rb b/app/models/mixins/purging_mixin.rb index 9adf053cb65..a1af6923249 100644 --- a/app/models/mixins/purging_mixin.rb +++ b/app/models/mixins/purging_mixin.rb @@ -117,7 +117,8 @@ def purge_orphans(fk_name, window) resource_table = connection.quote_table_name(klass.table_name) scope = joins("LEFT OUTER JOIN #{resource_table} ON #{table_name}.resource_id = #{resource_table}.id") - .where(resource_table => {:id => nil}, polymorphic_type_column => klass.name) + .where(resource_table => {:id => nil}) + .where("#{table_name}.#{connection.quote_column_name(polymorphic_type_column)} = #{connection.quote(klass.name)}") total += purge_in_batches(scope, window) end total