Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample Data #3

Closed
JaredBears opened this issue Oct 10, 2023 · 1 comment
Closed

Sample Data #3

JaredBears opened this issue Oct 10, 2023 · 1 comment

Comments

@JaredBears
Copy link

This is in relation to Photogram Industrial Part 2, when it is time to generate sample data.

With the Follow Requests, I noticed when running the provided code that it had users following themselves, which seems like unintentional behavior and causes the task to take longer than it should.

I solved this by adding next if first_user == second_user to the sample data generation task:

  users.each do |first_user|
    users.each do |second_user|
      next if first_user == second_user

I also added the following custom validation to the follow_requests table:

  validate :sender_cant_follow_self

  def sender_cant_follow_self
    if sender_id == recipient_id
      errors.add(:sender_id, "can't follow self")
    end
  end
@bpurinton
Copy link
Contributor

Well done! I'm going to leave off the custom validation (though I do like it) but I'll add the sample_data update to the lesson notes.

See these commits:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants