Modify seeds file to make sure every guest is part of a group
This commit is contained in:
parent
0814c7cab5
commit
191fcf4767
29
db/seeds.rb
29
db/seeds.rb
@ -28,32 +28,31 @@ Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
|
|||||||
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
|
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
|
||||||
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
|
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
|
||||||
|
|
||||||
300.times do
|
|
||||||
Guest.create!(first_name: Faker::Name.first_name,
|
|
||||||
last_name: Faker::Name.last_name,
|
|
||||||
email: Faker::Internet.email,
|
|
||||||
phone: Faker::PhoneNumber.cell_phone)
|
|
||||||
end
|
|
||||||
|
|
||||||
{
|
samples = {
|
||||||
close_family: 10,
|
close_family: 10,
|
||||||
family_1_group_a: 5,
|
family_1_group_a: 5,
|
||||||
family_1_group_b: 5,
|
family_1_group_b: 5,
|
||||||
family_2_group_a: 7,
|
family_2_group_a: 7,
|
||||||
family_2_group_b: 15,
|
family_2_group_b: 15,
|
||||||
previous_company: 5,
|
previous_company: 5,
|
||||||
new_company: 15,
|
new_company: 20,
|
||||||
college: 10,
|
college: 10,
|
||||||
high_school: 5,
|
high_school: 5,
|
||||||
childhood: 5,
|
childhood: 5,
|
||||||
basket_team: 20,
|
basket_team: 20,
|
||||||
soccer_team: 15,
|
soccer_team: 15,
|
||||||
dance_club: 10
|
dance_club: 10
|
||||||
}.each do |affinity_group, count|
|
}.each_with_object([]) do |(affinity_group, count), acc|
|
||||||
Guest.all.sample(count).each do |guest|
|
count.times { acc << affinity_group }
|
||||||
guest.affinity_group_list.add(affinity_group)
|
end
|
||||||
guest.save!
|
|
||||||
rescue => e
|
300.times do
|
||||||
binding.pry
|
guest = Guest.create!(first_name: Faker::Name.first_name,
|
||||||
end
|
last_name: Faker::Name.last_name,
|
||||||
|
email: Faker::Internet.email,
|
||||||
|
phone: Faker::PhoneNumber.cell_phone)
|
||||||
|
|
||||||
|
guest.affinity_group_list.add(samples.sample)
|
||||||
|
guest.save!
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user