Unfortunately, the DM does not provide a way to communicate why the destroy failed.
In most cases, the destruction failed due to its associations. The DM has a mechanism to avoid orphaned entries.
To avoid such destruction, you can use dm restrictions ( https://github.com/datamapper/dm-constraints ) to configure links to foreign keys of the true database level, which protects by default, but can be set instead of cascading deletes .
class List has n, :todos, :constraint => :destroy (or :destroy!) end
Unfortunately, at present, only PostgreSQL and MySQL support dm restrictions.
For another database, you can first check all associations and delete them, and then delete the model.
source share