1
0

account_relationship_severance_event.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. #
  3. # == Schema Information
  4. #
  5. # Table name: account_relationship_severance_events
  6. #
  7. # id :bigint(8) not null, primary key
  8. # account_id :bigint(8) not null
  9. # relationship_severance_event_id :bigint(8) not null
  10. # created_at :datetime not null
  11. # updated_at :datetime not null
  12. # followers_count :integer default(0), not null
  13. # following_count :integer default(0), not null
  14. #
  15. class AccountRelationshipSeveranceEvent < ApplicationRecord
  16. self.ignored_columns += %w(
  17. relationships_count
  18. )
  19. belongs_to :account
  20. belongs_to :relationship_severance_event
  21. has_many :severed_relationships, through: :relationship_severance_event
  22. delegate :type,
  23. :target_name,
  24. :purged,
  25. :purged?,
  26. to: :relationship_severance_event,
  27. prefix: false
  28. before_create :set_relationships_count!
  29. private
  30. def set_relationships_count!
  31. self.followers_count = severed_relationships.about_local_account(account).passive.count
  32. self.following_count = severed_relationships.about_local_account(account).active.count
  33. end
  34. end