You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
Let's say we have Book, Shelf and Author models. We can generate Authors and Books inside the loop, but how could we link Shelves?
Shelf.populate 20 do |shelf|
shelf.name = Populator.words(1..3).titleize
end
Author.populate 40 do |author|
Book.populate 0..40 do |book|
book.author_id = author.id
end
end
Any idea or suggestion ?
The text was updated successfully, but these errors were encountered:
I can see this is an old issue, yet still open.
Here is my suggestion to the problem
Shelf.populate 20 do |shelf|
shelf.name = Populator.words(1..3).titleize
end
Author.populate 40 do |author|
Book.populate 0..40 do |book|
book.author_id = author.id
book.shelf_id = Shelf.offset(rand(Shelf.count)).limit(1)
end
end
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Let's say we have Book, Shelf and Author models. We can generate Authors and Books inside the loop, but how could we link Shelves?
Shelf.populate 20 do |shelf|
shelf.name = Populator.words(1..3).titleize
end
Author.populate 40 do |author|
Book.populate 0..40 do |book|
book.author_id = author.id
end
end
Any idea or suggestion ?
The text was updated successfully, but these errors were encountered: