2017-11-17 23:16:48 +00:00
|
|
|
# frozen_string_literal: true
|
2023-02-20 05:58:28 +00:00
|
|
|
|
2017-11-17 23:16:48 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: list_accounts
|
|
|
|
#
|
2023-05-02 12:40:36 +00:00
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
# list_id :bigint(8) not null
|
|
|
|
# account_id :bigint(8) not null
|
|
|
|
# follow_id :bigint(8)
|
|
|
|
# follow_request_id :bigint(8)
|
2017-11-17 23:16:48 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
class ListAccount < ApplicationRecord
|
2018-01-19 19:56:47 +00:00
|
|
|
belongs_to :list
|
|
|
|
belongs_to :account
|
2019-11-04 12:02:01 +00:00
|
|
|
belongs_to :follow, optional: true
|
2023-05-02 12:40:36 +00:00
|
|
|
belongs_to :follow_request, optional: true
|
2017-11-17 23:16:48 +00:00
|
|
|
|
2017-12-05 22:02:27 +00:00
|
|
|
validates :account_id, uniqueness: { scope: :list_id }
|
|
|
|
|
2017-11-17 23:16:48 +00:00
|
|
|
before_validation :set_follow
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_follow
|
2023-05-02 12:40:36 +00:00
|
|
|
return if list.account_id == account.id
|
|
|
|
|
|
|
|
self.follow = Follow.find_by!(account_id: list.account_id, target_account_id: account.id)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
self.follow_request = FollowRequest.find_by!(account_id: list.account_id, target_account_id: account.id)
|
2017-11-17 23:16:48 +00:00
|
|
|
end
|
|
|
|
end
|