Reputation: 12666
How do I select soft-deleted records? For performance reasons, I need to update every record in my table before I do a migration.
This doesn't work:
SearchDefault.where('deleted_at IS NOT NULL')
because it produces this SQL:
SELECT COUNT(*) FROM "search_defaults" WHERE "search_defaults"."deleted_at" IS NULL AND (deleted_at IS NOT NULL)
I'll be happy with a solution that either selects every record, or every soft-deleted record.
Upvotes: 1
Views: 1464
Reputation: 16294
Presumably you have a default_scope
adding that condition. Try:
SearchDefault.unscoped.where('deleted_at IS NOT NULL')
Upvotes: 3