soft-destroyable
/soft-destroyable
Soft-delete ActiveRecord models with the `SoftDestroyable` concern installed by the rolemodel_rails `rolemodel:soft_destroyable` generator, including cascading soft deletes and restores across associations. Use when making a model soft-deletable, deleting or restoring a soft-destroyable record, querying around deleted records, or testing a soft-destroyable model.
- Author
- rolemodel ↗
- Repository
- skills ↗
- Licence
- MIT
- Last repository change
- 11.11.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 11.11.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Soft-delete ActiveRecord models with the `SoftDestroyable` concern installed by the rolemodel_rails `rolemodel:soft_destroyable` generator, including cascading soft deletes and restores across associations. Use when making a model soft-deletable, deleting or restoring a soft-destroyable record, querying around deleted records, or testing a soft-destroyable model.
Original author description
Soft-delete ActiveRecord models with the `SoftDestroyable` concern installed by the rolemodel_rails `rolemodel:soft_destroyable` generator, including cascading soft deletes and restores across associations. Use when making a model soft-deletable, deleting or restoring a soft-destroyable record, querying around deleted records, or testing a soft-destroyable model.
How it works
- Making a model soft-destroyable
- Rules
- Testing
SKILL.md preview
---
name: soft-destroyable
description: Soft-delete ActiveRecord models with the `SoftDestroyable` concern installed by the rolemodel_rails `rolemodel:soft_destroyable` generator, including cascading soft deletes and restores across associations. Use when making a model soft-deletable, deleting or restoring a soft-destroyable record, querying around deleted records, or testing a soft-destroyable model.
metadata:
triggers: "soft delete, soft destroy, soft_destroy, soft_destroyable, SoftDestroyable, deleted_at, kept, only_deleted, restore, cascade_soft_destroy, archive record, a soft destroyable"
---
# Soft Destroyable
`app/models/concerns/soft_destroyable.rb` marks records deleted by setting a `deleted_at` timestamp instead of removing rows. If the concern isn't there, run `bin/rails g rolemodel:soft_destroyable`.
## Making a model soft-destroyable
1. Add a nullable `deleted_at` datetime column (the generator doesn't add one).
2. Include the concern, and cascade to any associations that should go and come back with the parent:
```ruby
class Estimate < ApplicationRecord
include SoftDestroyable
has_many :line_items
cascade_soft_destroy :line_items # each associated model must also include SoftDestroyable
end
```
## Rules
- **Never add a `default_scope`.** The concern raises if you do. Scope explicitly with `Estimate.kept` / `Estimate.only_deleted`, including in associations and policy scopes.
- **Call `soft_destroy!`, not `destroy`.** `destroy` still hard-deletes. `soft_destroy!` raises `ActiveModel::ValidationError` if the update fails. `soft_destroy` returns falsy instead.
- **Restores match on timestamp.** `restore!` clears `deleted_at` and restores cascaded children *soft-destroyed at the same moment*. Children deleted earlier on their own stay deleted. Restore failures only surface at the top level.
- `soft_destroyed?` reports the state. The class-level `soft_destroy` / `restore(timestamp)` act on relations.
- If assigned attributes include `_soft_destroy`, every other attribute is dropped and only `_soft_destroy` is assigned. The model must define a `_soft_destroy=` writer, or that assignment raises `ActiveModel::UnknownAttributeError`.
## Testing
Use the shared example installed at `spec/support/shared_examples/soft_destroyable_behavior.rb`:
```ruby
RSpec.describe Estimate do
it_behaves_like 'a soft destroyable', :estimate,
factory_traits: [:with_line_items],
dependent_destroy_relations: [:line_items]
end
```
The factory (plus traits) must build records that have the cascaded associations populated, or the dependent examples have nothing to check.
Versions
The database has no other skills named soft-destroyable.
Database snapshot: 13.11.2026 · package version c65dcbeb9cf4 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100soft-delete
Reference for Kavo's soft delete, restore, and purge behavior — strategy resolution (auto/soft/hard), enabling restoreOne/purgeOne, read semantics and withDeleted, and edge cases (unique constraints, cascades). Use when configuring delete, wiring restore/purge routes, or… - 81rails-ai:models
Use when designing Rails models - ActiveRecord patterns, validations, callbacks, scopes, associations, concerns, query objects, form objects - 96soft-lint
Write, reword or tune a soft-lint rule, the plain-English yes/no question a classifier asks about the lines a diff adds. Use when adding or changing a rule in a .soft-lint.json, or when a rule fires on legitimate code or misses a real case. - 100activerecord
This skill should be used when the user asks to "write a migration", "add a column", "add column to table", "create an index", "add a foreign key", "set up associations", "fix N+1 queries", "optimize queries", "add validations", "create callbacks", "use eager loading", or… - 100soft-deleted-object-access
Verify that soft-deleted objects disappear for everyone except an authorized restore path, instead of lingering behind a stale check. Use when the product marks objects deleted without removing them, such as trash, archive or recycle behaviour