Reys3.0 da bir nechta yozuvlarni qanday kiritish kerak

Jadvalda bir nechta yozuvni qanday qo'shish kerak? plz menga biron bir misol dasturini aytib bering.

5

1 javoblar

Siz operatsiyalardan foydalanishingiz mumkin

titles = ["T-Shirt", "Boots", "Cap"]

ActiveRecord::Base.transaction do
  titles.each do |title|
    Thing.create(:title => title)
  end
end

Ot bir sql so'rovini bajaradi:

query = []
titles.each do |title|
  query << "('#{title}')"
end
sql = "INSERT INTO things ('title') VALUES #{query.join(", ")}"
ActiveRecord::Base.connection.execute(sql)

Juda qiziq maqola

http : //www.coffeepowered.net/2009/01/23/mass-inserting-data-in-rails-without-killing-your-performance/

5
qo'shib qo'ydi
aloqa buzilgan
qo'shib qo'ydi muallif KoU_warch, manba