favourite.rb 714 B

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