Class: Markable::Mark

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/models/mark.rb

Class Method Summary collapse

Class Method Details

.delete_orphansNumber

Delete orphan marks

Marks are deleted when marker or markable record is destroyed. However, in some circumstances, some marks may reference non existing records (for instance if the record has been deleted - not destroyed).

Note: this method is not efficient but this should not be a problem as it should be used as a maintenance operation only.

Returns:

  • (Number)

    Deleted orphan marks count



17
18
19
20
21
22
23
# File 'lib/models/mark.rb', line 17

def self.delete_orphans
  Markable::Mark.all.delete_if { |mark|
    mark.marker && mark.markable
  }.each { |orphan|
    Markable::Mark.delete_all orphan.attributes
  }.count
end