2024-03-20 15:37:21 +00:00
|
|
|
# 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
|
2024-03-22 15:44:31 +00:00
|
|
|
# followers_count :integer default(0), not null
|
|
|
|
# following_count :integer default(0), not null
|
2024-03-20 15:37:21 +00:00
|
|
|
#
|
|
|
|
class AccountRelationshipSeveranceEvent < ApplicationRecord
|
2024-03-22 15:44:31 +00:00
|
|
|
self.ignored_columns += %w(
|
|
|
|
relationships_count
|
|
|
|
)
|
|
|
|
|
2024-03-20 15:37:21 +00:00
|
|
|
belongs_to :account
|
|
|
|
belongs_to :relationship_severance_event
|
|
|
|
|
2024-03-22 14:43:35 +00:00
|
|
|
has_many :severed_relationships, through: :relationship_severance_event
|
|
|
|
|
|
|
|
delegate :type,
|
2024-03-20 17:14:53 +00:00
|
|
|
:target_name,
|
|
|
|
:purged,
|
|
|
|
:purged?,
|
|
|
|
to: :relationship_severance_event,
|
|
|
|
prefix: false
|
2024-03-20 15:37:21 +00:00
|
|
|
|
|
|
|
before_create :set_relationships_count!
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_relationships_count!
|
2024-03-22 15:44:31 +00:00
|
|
|
self.followers_count = severed_relationships.about_local_account(account).passive.count
|
|
|
|
self.following_count = severed_relationships.about_local_account(account).active.count
|
2024-03-20 15:37:21 +00:00
|
|
|
end
|
|
|
|
end
|