sirramongabriel
sirramongabriel

Reputation: 621

rake db:seed_fu not populating database

I'm using the seed-fu gem and am able to get 2 files to seed the db successfully. The following file, while it produces output in the terminal, isn't populating the db:

# residents.rb


Resident.seed do |r|
  r.account_id = 1
  r.employee_id = 1
  r.first_name = "solomon"
  r.last_name = "gibsom"
  r.gender = "Male"
  r.dob = Date.parse("1937-02-20")
  r.case_number = "H-3827-JKZ-0329"
  r.veteran_status_number = "G-15 classified"
  r.marital_status = "Married"
  r.arrival_date = Date.today
  r.religious_preferences = "None"
  r.insurance_info = "Medicaid"
  r.burial_provisions = "Cremation"
  r.admission_weight = "121 lbs"
  r.admission_height = "5ft 9in"
  r.allergies = "Corn, wheat and peanut allergies"
end

Address.seed do |r|
  r.account_id = 1
  r.employee_id = 1
  r.resident_id = 1
  r.street_address = "55298 solomon hills blvd"
  r.city = "Flint"
  r.state = "MI"
  r.zip = "48289"
end

PrimaryPhone.seed do |r|
  r.account_id = 1
  r.employee_id = 1
  r.resident_id = 1
  r.area_code = "810"
  r.number = "565-0255"
end

Terminal output:

Terminal output

The output looks good so I check for the records in the console:

Rails console confirms no objects committed

I'm sort of at a loss on where further to look to check for errors.

Here are two files that work as expected:

#accounts.rb

Account.seed do |a|
  a.facility_name = "Chuck Norris AFC"
end

#admins.rb

Employee.seed do |a|
  a.account_id = 1
  a.is_admin = true
  a.first_name = "kenneth"
  a.last_name = "the paige"
  a.email = "[email protected]"
  a.password = "12345678"
  a.password_confirmation = "12345678"
  a.dob = Date.parse("1965-05-05")
  a.gender = "Male"
end

Address.seed do |address|
  address.account_id = 1
  address.employee_id = 1
  address.street_address = "123 Chuckleburger dr."
  address.city = "New York"
  address.state = "NY"
  address.zip = "00001"
end

some background:

I'm using seed-fu ~>2.3, residents.rb lives inside of db/fixtures/, and the rails version is 4.2

Thank you in advance for having a look!

Upvotes: 0

Views: 163

Answers (1)

Jeiwan
Jeiwan

Reputation: 954

Pay attention to the SQL queries printed in the console when you run Resident.all: they have condition WHERE resident.account_id is NULL. But in seeds file Resident has account_id = 1.

You might've set default_scope for Resident model. Try running Resident.unscoped.all or remove the default scope.

Upvotes: 1

Related Questions