A simple ActiveRecord mixin for soft-deleting records by flagging them as discarded, without overriding ActiveRecord methods.
Discard is a Ruby gem that implements soft deletes for ActiveRecord models by adding a `discarded_at` timestamp column. It allows records to be marked as discarded (hidden) instead of permanently deleted, making it easy to restore data or maintain referential integrity. The gem provides a clean, non-invasive API that avoids overriding ActiveRecord's core methods.
Ruby on Rails developers who need soft-delete functionality in their ActiveRecord models without the complexity and side effects of other gems like Paranoia. It's ideal for applications where data retention and easy restoration are important.
Developers choose Discard because it offers a simpler, more predictable approach to soft deletes compared to alternatives. It doesn't add default scopes or override ActiveRecord methods, reducing unexpected behavior and making it easier to work with associations and queries.
๐๐ Soft deletes for ActiveRecord done right
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Avoids overriding ActiveRecord's destroy or delete methods, preventing unexpected behavior and making integration predictable, as highlighted in the README's comparison to Paranoia.
Provides .kept, .discarded, and .with_discarded scopes for easy record filtering, demonstrated in usage examples for straightforward hidden record management.
Allows explicit handling of associations via callbacks or SQL joins rather than automatic recursive discarding, giving developers fine-grained control as shown in the 'Working with associations' section.
Supports using existing columns like deleted_at for compatibility with other soft-delete gems, mentioned in the 'Custom column' section for seamless transitions.
Does not automatically adjust ActiveRecord counter cache columns to exclude discarded records, requiring manual workarounds for accurate counts, as admitted in the 'Non-features' section.
discard_all and undiscard_all run callbacks and validations per record, which can be slow for large datasets, forcing developers to use raw SQL updates for performance, as warned in the 'Performance tuning' section.
Requires custom code like SQL joins or callbacks for dependent association logic, adding complexity compared to gems that offer automatic recursive deletes out of the box.
Discard is an open-source alternative to the following products: