brandoncc said about 6 years ago on ActiveRecord Tricks :
You retrieve 37 users, not messages... Other than that, good episode.

hackvan said about 6 years ago on ActiveRecord Tricks :
awesome tricks, thanks a lot!

Christof Spies said over 5 years ago on ActiveRecord Tricks :
use `.ids` instead of `.pluck(:id)` ;)

TheeGrassHopper said over 3 years ago on ActiveRecord Tricks :
db:seed doesn't populate any of my Users or my Messages? 
Status populates but not the others? hummm

David Kimura PRO said over 3 years ago on ActiveRecord Tricks :
  add a bang to User.create

User.create! do |user|
 ...
end

This won't fix the problem, but will fail and you can see what the error is.

TheeGrassHopper said over 3 years ago on ActiveRecord Tricks :
20.times do
  User.create! do |user|
    user.first_name = Faker::Name.first_name
    user.last_name = Faker::Name.last_name
    user.email = Faker::Internet.email
    user.status = Status.all.sample
  end
end
When I run the above in the console I get no errors but User.all is empty then Message.create! breaks with "ActiveRecord::RecordInvalid: Validation failed: User must exist" error. It's as if it never saves the Users to the database.

David Kimura PRO said over 3 years ago on ActiveRecord Tricks :
You probably have some other association on the user (belongs_to) which is causing the user to not save.

Login to Comment