Fix rails db:seed error (#11272)
rails db:seed sometimes tries to create two 'vomit' reactions on the same Article which is prohibited by the validations on the Reaction model.
This commit is contained in:
parent
474ba1688f
commit
ad747a271f
1 changed files with 8 additions and 1 deletions
|
|
@ -450,9 +450,16 @@ seeder.create_if_none(FeedbackMessage) do
|
|||
)
|
||||
|
||||
3.times do
|
||||
article_id = Article
|
||||
.left_joins(:reactions)
|
||||
.where.not(articles: { id: Reaction.article_vomits.pluck(:reactable_id) })
|
||||
.order(Arel.sql("RANDOM()"))
|
||||
.first
|
||||
.id
|
||||
|
||||
Reaction.create!(
|
||||
category: "vomit",
|
||||
reactable_id: Article.order(Arel.sql("RANDOM()")).first.id,
|
||||
reactable_id: article_id,
|
||||
reactable_type: "Article",
|
||||
user_id: mod.id,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue