闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
744 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: favourites
  5. #
  6. # id :bigint(8) not null, primary key
  7. # created_at :datetime not null
  8. # updated_at :datetime not null
  9. # account_id :bigint(8) not null
  10. # status_id :bigint(8) not null
  11. #
  12. class Favourite < ApplicationRecord
  13. include Paginable
  14. update_index('statuses#status', :status) if Chewy.enabled?
  15. belongs_to :account, inverse_of: :favourites
  16. belongs_to :status, inverse_of: :favourites, counter_cache: true
  17. has_one :notification, as: :activity, dependent: :destroy
  18. validates :status_id, uniqueness: { scope: :account_id }
  19. before_validation do
  20. self.status = status.reblog if status&.reblog?
  21. end
  22. end