ruby on rails - Get data in batch using ActiveRecord -
i create rails app , fetch data batch starting specific point. use ar , table structure looks following:
create_table(:types) |t| t.string :name, null: false t.string :type, null: false t.string :type_id, null: false t.text :metadata t.timestamps end
to data use type_id in following format (guid):
"b2d506fd-409d-4ec7-b02f-c6d2295c7edd"
i fetch specific count of data, ascending or descending ,starting specific type_id. more specific want do this:
model.get_batch(type_id: type, count: 20).desc
can in activerecord?
you can use activerecord::batches find records in batches
example
model.where('your condition').find_in_batches(start: 2000, batch_size: 2000) |group| # batch end
Comments
Post a Comment