# Soft delete
A way to mark record in database as deleted, but not delete it completely (mostly needed for audition and link integrity)
/lib/common/sql_relation_reading_extension.rb
module ROM::SQL::Relation::Reading
def not_deleted
new(dataset.where(deleted_at: nil))
end
end
1
2
3
4
5
6
7
2
3
4
5
6
7
TIP
Don't forget to require this file somewhere in environment.rb
now you can do queries like this
class PostRepository < Hanami::Repository
def find_by_uuid(uuid)
posts.where(uuid: uuid).not_deleted.one
end
1
2
3
4
2
3
4