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