account_associations.rb 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # frozen_string_literal: true
  2. module AccountAssociations
  3. extend ActiveSupport::Concern
  4. included do
  5. # Local users
  6. has_one :user, inverse_of: :account, dependent: :destroy
  7. # Identity proofs
  8. has_many :identity_proofs, class_name: 'AccountIdentityProof', dependent: :destroy, inverse_of: :account
  9. has_many :devices, dependent: :destroy, inverse_of: :account
  10. # Timelines
  11. has_many :statuses, inverse_of: :account, dependent: :destroy
  12. has_many :favourites, inverse_of: :account, dependent: :destroy
  13. has_many :bookmarks, inverse_of: :account, dependent: :destroy
  14. has_many :mentions, inverse_of: :account, dependent: :destroy
  15. has_many :notifications, inverse_of: :account, dependent: :destroy
  16. has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
  17. has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy
  18. # Pinned statuses
  19. has_many :status_pins, inverse_of: :account, dependent: :destroy
  20. has_many :pinned_statuses, -> { reorder('status_pins.created_at DESC') }, through: :status_pins, class_name: 'Status', source: :status
  21. # Endorsements
  22. has_many :account_pins, inverse_of: :account, dependent: :destroy
  23. has_many :endorsed_accounts, through: :account_pins, class_name: 'Account', source: :target_account
  24. # Media
  25. has_many :media_attachments, dependent: :destroy
  26. has_many :polls, dependent: :destroy
  27. # Report relationships
  28. has_many :reports, dependent: :destroy, inverse_of: :account
  29. has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
  30. has_many :report_notes, dependent: :destroy
  31. has_many :custom_filters, inverse_of: :account, dependent: :destroy
  32. # Moderation notes
  33. has_many :account_moderation_notes, dependent: :destroy, inverse_of: :account
  34. has_many :targeted_moderation_notes, class_name: 'AccountModerationNote', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
  35. has_many :account_warnings, dependent: :destroy, inverse_of: :account
  36. has_many :targeted_account_warnings, class_name: 'AccountWarning', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
  37. # Lists (that the account is on, not owned by the account)
  38. has_many :list_accounts, inverse_of: :account, dependent: :destroy
  39. has_many :lists, through: :list_accounts
  40. # Lists (owned by the account)
  41. has_many :owned_lists, class_name: 'List', dependent: :destroy, inverse_of: :account
  42. # Account migrations
  43. belongs_to :moved_to_account, class_name: 'Account', optional: true
  44. has_many :migrations, class_name: 'AccountMigration', dependent: :destroy, inverse_of: :account
  45. has_many :aliases, class_name: 'AccountAlias', dependent: :destroy, inverse_of: :account
  46. # Hashtags
  47. has_and_belongs_to_many :tags
  48. has_many :featured_tags, -> { includes(:tag) }, dependent: :destroy, inverse_of: :account
  49. # Account deletion requests
  50. has_one :deletion_request, class_name: 'AccountDeletionRequest', inverse_of: :account, dependent: :destroy
  51. end
  52. end