Skip to content

Commit

Permalink
Update README with example for as_relation option
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianna-chang-shopify committed May 11, 2021
1 parent 5a00479 commit 5d7ddce
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,29 @@ class BatchesJob < ApplicationJob

def each_iteration(batch_of_comments, product_id)
# batch_of_comments will contain batches of 100 records
Comment.where(id: batch_of_comments.map(&:id)).update_all(deleted: true)
batch_of_comments.each do |comment|
DeleteCommentJob.perform_later(comment)
end
end
end
```

```ruby
class BatchesAsRelationJob < ApplicationJob
include JobIteration::Iteration

def build_enumerator(product_id, cursor:)
enumerator_builder.active_record_on_batches(
Product.find(product_id).comments,
cursor: cursor,
batch_size: 100,
as_relation: true,
)
end

def each_iteration(batch_of_comments, product_id)
# batch_of_comments will be a Comment::ActiveRecord_Relation
batch_of_comments.update_all(deleted: true)
end
end
```
Expand Down

0 comments on commit 5d7ddce

Please sign in to comment.