Add circle editor
This commit is contained in:
parent
c97e63bb18
commit
b0854b1dd8
33 changed files with 1671 additions and 31 deletions
39
app/models/circle_account.rb
Normal file
39
app/models/circle_account.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: circle_accounts
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# circle_id :bigint(8)
|
||||
# account_id :bigint(8) not null
|
||||
# follow_id :bigint(8) not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class CircleAccount < ApplicationRecord
|
||||
belongs_to :circle
|
||||
belongs_to :account
|
||||
belongs_to :follow
|
||||
|
||||
validates :account_id, uniqueness: { scope: :circle_id }
|
||||
validate :validate_relationship
|
||||
|
||||
before_validation :set_follow
|
||||
|
||||
private
|
||||
|
||||
def set_follow
|
||||
return if circle.account_id == account.id
|
||||
|
||||
self.follow = Follow.find_by!(account_id: account.id, target_account_id: circle.account_id)
|
||||
end
|
||||
|
||||
def validate_relationship
|
||||
return if circle.account_id == account_id
|
||||
|
||||
errors.add(:account_id, 'follow relationship missing') if follow_id.nil?
|
||||
errors.add(:follow, 'mismatched accounts') if follow_id.present? && follow.account_id != account_id
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue