Welcome to mirror list, hosted at ThFree Co, Russian Federation.

aspect_membership.rb « models « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87bc6c57451fc25efb88e7e52112964fead8c43a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class AspectMembership < ApplicationRecord
  belongs_to :aspect
  belongs_to :contact
  has_one :user, :through => :contact
  has_one :person, :through => :contact

  before_destroy do
    user&.disconnect(contact) if contact&.aspects&.size == 1
    true
  end

  def as_json(opts={})
    {
      :id => self.id,
      :person_id  => self.person.id,
      :contact_id => self.contact.id,
      :aspect_id  => self.aspect_id,
      :aspect_ids => self.contact.aspects.map{|a| a.id}
    }
  end
end