follow.rb 779 B

12345678910111213141516171819202122232425262728
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: follows
  5. #
  6. # id :integer not null, primary key
  7. # account_id :integer not null
  8. # target_account_id :integer not null
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. #
  12. class Follow < ApplicationRecord
  13. include Paginable
  14. belongs_to :account, counter_cache: :following_count, required: true
  15. belongs_to :target_account,
  16. class_name: 'Account',
  17. counter_cache: :followers_count,
  18. required: true
  19. has_one :notification, as: :activity, dependent: :destroy
  20. validates :account_id, uniqueness: { scope: :target_account_id }
  21. scope :recent, -> { reorder(id: :desc) }
  22. end