list_account.rb 589 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: list_accounts
  5. #
  6. # id :bigint(8) not null, primary key
  7. # list_id :bigint(8) not null
  8. # account_id :bigint(8) not null
  9. # follow_id :bigint(8) not null
  10. #
  11. class ListAccount < ApplicationRecord
  12. belongs_to :list
  13. belongs_to :account
  14. belongs_to :follow
  15. validates :account_id, uniqueness: { scope: :list_id }
  16. before_validation :set_follow
  17. private
  18. def set_follow
  19. self.follow = Follow.find_by(account_id: list.account_id, target_account_id: account.id)
  20. end
  21. end