Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20170914212336_cleanup_invalid_polls.rb « migrate « db - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d7cda97f943fbf7e2b9ed945ea6b5c79ba223bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class CleanupInvalidPolls < ActiveRecord::Migration[5.1]
  class Poll < ApplicationRecord
    has_many :poll_answers, dependent: :destroy
    has_many :poll_participations, dependent: :destroy
  end
  class PollAnswer < ApplicationRecord
    belongs_to :poll
    has_many :poll_participations
  end
  class PollParticipation < ApplicationRecord
    belongs_to :poll
    belongs_to :poll_answer
  end

  def up
    Poll.joins("LEFT OUTER JOIN posts ON posts.id = polls.status_message_id")
        .where("posts.id IS NULL").destroy_all
  end
end