module Avram::SoftDelete::Query

Overview

Add methods for querying/updating soft deleted and kept records.

First include the model module in your model: Avram::SoftDelete::Model

Then add this module your query

class ArticleQuery < Article::BaseQuery
  include Avram::SoftDelete::Query
end

Defined in:

avram/soft_delete/query.cr

Instance Method Summary

Instance Method Detail

def only_kept #

Only return kept records

Kept records are considered "kept/not soft deleted" if the #soft_deleted_at column is nil


[View source]
def only_soft_deleted #

Only return soft deleted records

Soft deleted records are considered "soft deleted" if the #soft_deleted_at column has a non-nil value


[View source]
def restore : Int64 #

Bulk restore records

Example

This will restore Article records updated in the last week:

ArticleQuery.new.updated_at.gt(1.week.ago).restore

[View source]
def soft_delete #

Bulk soft delete records

Example

This will soft delete all Article record older than 1 year:

ArticleQuery.new.created_at.lt(1.year.ago).soft_delete

[View source]
abstract def soft_deleted_at #

[View source]
def with_soft_deleted #

Returns all records

This works be removing where clauses for the #soft_deleted_at column. That means you can do MyQuery.new.only_kept.with_soft_deleted and you will get all records, not just the kept ones.


[View source]