Sha256: 081b8d5b65cc79e9dc0aa7ce82ba951f8d70754126435b485361de3d3d8e21f6

Contents?: true

Size: 1 KB

Versions: 15

Compression:

Stored size: 1 KB

Contents

module Dorsale
  module CustomerVault
    class Person < ActiveRecord::Base
      self.abstract_class = true

      after_destroy :destroy_links

      acts_as_taggable

      def tags_on(*args)
        super(*args).order(:name)
      end

      has_many :comments, -> { order("id DESC") }, class_name: ::Dorsale::Comment, as: :commentable, dependent: :destroy
      has_one :address, class_name: ::Dorsale::Address, as: :addressable, inverse_of: :addressable, dependent: :destroy
      has_many :tasks, class_name: ::Dorsale::Flyboy::Task, as: :taskable, dependent: :destroy
      accepts_nested_attributes_for :address, allow_destroy: true

      def links
        a = Link.where(alice_id: self.id, alice_type: self.class).map {|l| {title: l.title, person: l.bob, origin: l}}
        b = Link.where(bob_id: self.id, bob_type: self.class).map {|l| {title: l.title, person: l.alice, origin: l}}
        return a + b
      end

      def destroy_links
        links.map{ |l| l[:origin].destroy! }
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dorsale-2.2.11 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.10 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.9 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.8 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.6 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.5 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.4 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.3 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.2 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.1 app/models/dorsale/customer_vault/person.rb
dorsale-2.2.0 app/models/dorsale/customer_vault/person.rb
dorsale-2.1.15 app/models/dorsale/customer_vault/person.rb
dorsale-2.1.14 app/models/dorsale/customer_vault/person.rb
dorsale-2.1.13 app/models/dorsale/customer_vault/person.rb
dorsale-2.1.12 app/models/dorsale/customer_vault/person.rb