Clear ORM
Search…
Each and Fetch
Collection inherits from Enumerable(T) therefore it allows all the methods defined by the module. When calling enumeration via each or mapor any other methods defined in Enumerable(T), the collection is resolved and SQL request is triggered.

Collection(T)#each

Return the list of models returned by the request:
1
Post.query.where(user_id: 1).each do |posts|
2
# Do something with the posts
3
end
Copied!

Collection(T)#fetch

Fetch stands for iterating through hash instead of model. While offering less features (as we do not connect a model to the data), it offers best performances, as no extra-allocations are made:
1
Post.query.where(user_id: 1).fetch do |posts|
2
puts "#{post["id"]} - #{post["name"]}"
3
end
Copied!