Module: ZombieRecord::Restorable::ClassMethods

Defined in:
lib/zombie_record/restorable.rb

Instance Method Summary collapse

Instance Method Details

#deletedObject

Scopes the relation to only include deleted records.

Returns an ActiveRecord::Relation.



171
172
173
# File 'lib/zombie_record/restorable.rb', line 171

def deleted
  with_deleted.where("#{quoted_table_name}.deleted_at IS NOT NULL")
end

#with_deletedObject

Scopes the relation to include both active and deleted records.

Returns an ActiveRecord::Relation.



178
179
180
181
182
183
184
185
186
187
188
# File 'lib/zombie_record/restorable.rb', line 178

def with_deleted
  if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0
    all.
      tap {|relation| relation.default_scoped = false }.
      extending(WithDeletedAssociationsWrapper)
  else
    all.
      unscope(where: :deleted_at).
      extending(WithDeletedAssociationsWrapper)
  end
end