1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/person.rb

50 lines
883 B
Ruby
Raw Normal View History

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-25 20:56:31 -04:00
################
# Associations #
################
2019-08-28 12:59:39 -04:00
has_one_attached :photo
belongs_to :contact_list
2019-06-26 20:21:37 -04:00
has_one :account
2018-12-14 23:20:13 -05:00
has_many :all_relationships,
-> { order(from_date: :asc) },
class_name: 'Relationship',
inverse_of: :person
2019-04-28 09:08:02 -04:00
has_one :current_relationship,
-> { order(from_date: :desc) },
class_name: 'Relationship',
inverse_of: :person
has_many :person_comments
2019-07-15 17:19:11 -04:00
has_many :passports
2019-06-26 20:21:37 -04:00
###############
# Validations #
###############
validates :contact_list, uniqueness: true
2019-07-26 00:46:01 -04:00
2019-08-28 12:59:39 -04:00
validates :photo, allow_nil: true, image: 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