Class: Upgrade::ConvertCollectionsJob

Inherits:
IterationJob
  • Object
show all
Defined in:
app/jobs/upgrade/convert_collections_job.rb

Instance Method Summary collapse

Instance Method Details

#build_enumerator(cursor:) ⇒ Object



6
7
8
9
# File 'app/jobs/upgrade/convert_collections_job.rb', line 6

def build_enumerator(cursor:)
  # Find models that have something in the old collection field
  enumerator_builder.active_record_on_records(Model.where.not(collection_id: nil), cursor: cursor)
end

#each_iteration(record) ⇒ Object



11
12
13
14
15
16
17
# File 'app/jobs/upgrade/convert_collections_job.rb', line 11

def each_iteration(record)
  collection = Collection.find(record.collection_id)
  # Add to the new association
  record.collections << collection unless collection.in?(record.collections)
  # Remove the old collection ID without validation, callbacks, or touching the date
  record.update_column :collection_id, nil # rubocop:disable Rails/SkipsModelValidations
end