79480810

Date: 2025-03-03 11:08:02
Score: 0.5
Natty:
Report link

Best way since Rails 6 is to use upsert_all/insert_all.

posts = []
10000.times do |iter|
  # construct a hash of our Post values
  posts << { title: Faker::Company.name, body: Faker::Company.bs }
end

# create all our Posts with a single INSERT
Post.upsert_all posts
puts "finished seeding the database"

This guy did some research on this: https://railsnotes.xyz/blog/seed-your-database-with-the-faker-gem

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
Posted by: theredled