2018-12-09 22:32:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Person < ApplicationRecord
|
2019-03-26 16:40:53 -04:00
|
|
|
include Nameable
|
2019-03-26 16:09:10 -04:00
|
|
|
|
2019-03-25 20:56:31 -04:00
|
|
|
################
|
|
|
|
# Associations #
|
|
|
|
################
|
|
|
|
|
2019-06-26 20:21:37 -04:00
|
|
|
belongs_to :contacts_list
|
|
|
|
|
2019-07-20 06:25:23 -04:00
|
|
|
has_one :account
|
2018-12-14 23:20:13 -05:00
|
|
|
|
2019-07-20 08:16:48 -04:00
|
|
|
has_many :all_relationships,
|
2019-07-20 02:22:47 -04:00
|
|
|
-> { order(from_date: :asc) },
|
2019-07-20 08:16:48 -04:00
|
|
|
class_name: 'Relationship',
|
2019-07-20 06:25:23 -04:00
|
|
|
inverse_of: :person
|
2019-04-28 09:08:02 -04:00
|
|
|
|
2019-04-28 10:20:28 -04:00
|
|
|
has_one :current_relationship,
|
2019-07-20 02:22:47 -04:00
|
|
|
-> { order(from_date: :desc) },
|
2019-04-28 10:20:28 -04:00
|
|
|
class_name: 'Relationship',
|
2019-07-20 06:25:23 -04:00
|
|
|
inverse_of: :person
|
2019-04-28 10:20:28 -04:00
|
|
|
|
2019-07-20 08:01:24 -04:00
|
|
|
has_one :current_regional_office,
|
2019-07-20 07:56:26 -04:00
|
|
|
inverse_of: :all_people,
|
2019-07-20 05:53:51 -04:00
|
|
|
through: :current_relationship,
|
2019-07-20 06:25:23 -04:00
|
|
|
source: :regional_office
|
2019-07-20 05:53:51 -04:00
|
|
|
|
2019-07-20 06:25:23 -04:00
|
|
|
has_many :person_comments
|
2019-07-15 17:19:11 -04:00
|
|
|
|
2019-07-20 06:25:23 -04:00
|
|
|
has_many :passports
|
2019-01-30 22:04:42 -05:00
|
|
|
|
2019-06-26 20:21:37 -04:00
|
|
|
###############
|
|
|
|
# Validations #
|
|
|
|
###############
|
|
|
|
|
|
|
|
validates :contacts_list, uniqueness: true
|
2019-07-26 00:46:01 -04:00
|
|
|
|
|
|
|
###########
|
|
|
|
# Methods #
|
|
|
|
###########
|
|
|
|
|
|
|
|
def full_name
|
|
|
|
[
|
|
|
|
last_name,
|
|
|
|
first_name,
|
|
|
|
middle_name,
|
|
|
|
].map(&:presence).compact.join(' ').freeze
|
|
|
|
end
|
2018-12-09 22:32:35 -05:00
|
|
|
end
|