2017-11-18 08:16:48 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: list_accounts
|
|
|
|
#
|
2018-04-23 18:29:17 +09:00
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
# list_id :bigint(8) not null
|
|
|
|
# account_id :bigint(8) not null
|
2019-11-04 21:02:01 +09:00
|
|
|
# follow_id :bigint(8)
|
2017-11-18 08:16:48 +09:00
|
|
|
#
|
|
|
|
|
|
|
|
class ListAccount < ApplicationRecord
|
2018-01-20 04:56:47 +09:00
|
|
|
belongs_to :list
|
|
|
|
belongs_to :account
|
2019-11-04 21:02:01 +09:00
|
|
|
belongs_to :follow, optional: true
|
2017-11-18 08:16:48 +09:00
|
|
|
|
2017-12-06 07:02:27 +09:00
|
|
|
validates :account_id, uniqueness: { scope: :list_id }
|
|
|
|
|
2017-11-18 08:16:48 +09:00
|
|
|
before_validation :set_follow
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_follow
|
2019-11-04 21:02:01 +09:00
|
|
|
self.follow = Follow.find_by!(account_id: list.account_id, target_account_id: account.id) unless list.account_id == account.id
|
2017-11-18 08:16:48 +09:00
|
|
|
end
|
|
|
|
end
|