summaryrefslogtreecommitdiffstats
path: root/app/models/account_relationship_severance_event.rb
blob: c1269fad6d9152d982ac0fa4b306051e89c80b8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

#
# == Schema Information
#
# Table name: account_relationship_severance_events
#
#  id                              :bigint(8)        not null, primary key
#  account_id                      :bigint(8)        not null
#  relationship_severance_event_id :bigint(8)        not null
#  created_at                      :datetime         not null
#  updated_at                      :datetime         not null
#  followers_count                 :integer          default(0), not null
#  following_count                 :integer          default(0), not null
#
class AccountRelationshipSeveranceEvent < ApplicationRecord
  self.ignored_columns += %w(
    relationships_count
  )

  belongs_to :account
  belongs_to :relationship_severance_event

  has_many :severed_relationships, through: :relationship_severance_event

  delegate :type,
           :target_name,
           :purged,
           :purged?,
           to: :relationship_severance_event,
           prefix: false

  before_create :set_relationships_count!

  private

  def set_relationships_count!
    self.followers_count = severed_relationships.about_local_account(account).passive.count
    self.following_count = severed_relationships.about_local_account(account).active.count
  end
end