Commit fc41a7caaf8ed1f47edcc44b20f546f54bb5a5dd
1 parent
d5f35d81
Exists in
master
and in
1 other branch
simplify safely associate appearance
Showing
1 changed file
with
2 additions
and
6 deletions
Show diff stats
app/models/visitor.rb
| ... | ... | @@ -86,12 +86,8 @@ class Visitor < ActiveRecord::Base |
| 86 | 86 | # Manually update Appearance with id to ensure no double votes for a |
| 87 | 87 | # single appearance. Only update the answerable_id if it is NULL. |
| 88 | 88 | # If we can't find any rows to update, then this object should be invalid. |
| 89 | - rows_updated = Appearance.update_all("answerable_id = #{object.id}, answerable_type = '#{object.class.to_s}'", "id = #{appearance.id} AND answerable_id IS NULL") | |
| 90 | - if rows_updated === 1 | |
| 91 | - # update relationship the ActiveRecord way, now | |
| 92 | - # that we know it is safe to do so | |
| 93 | - object.update_attributes!(:appearance => appearance) | |
| 94 | - else | |
| 89 | + rows_updated = Appearance.update_all("answerable_id = #{object.id}, answerable_type = '#{object.class.to_s}', updated_at = '#{Time.now.utc.to_s(:db)}'", "id = #{appearance.id} AND answerable_id IS NULL") | |
| 90 | + if rows_updated != 1 | |
| 95 | 91 | object.update_attributes!(:valid_record => false, :validity_information => "Appearance #{appearance.id} already answered") |
| 96 | 92 | end |
| 97 | 93 | end | ... | ... |