2018-11-26 08:39:32 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-06 14:37:45 -05:00
|
|
|
class MembershipApp < ApplicationRecord
|
2019-03-25 20:56:31 -04:00
|
|
|
################
|
|
|
|
# Associations #
|
|
|
|
################
|
|
|
|
|
2018-12-13 00:36:00 -05:00
|
|
|
belongs_to :account, inverse_of: :own_membership_app
|
2018-12-01 13:55:36 -05:00
|
|
|
belongs_to :country_state, optional: true
|
|
|
|
|
2018-12-06 18:00:15 -05:00
|
|
|
has_one :regional_office, through: :country_state
|
2018-12-14 23:20:13 -05:00
|
|
|
has_one :person, through: :account, inverse_of: :own_membership_app
|
2018-12-06 18:00:15 -05:00
|
|
|
|
2019-03-25 20:56:31 -04:00
|
|
|
###############
|
|
|
|
# Validations #
|
|
|
|
###############
|
|
|
|
|
2018-12-05 21:46:32 -05:00
|
|
|
validates :email, presence: true, format: Devise.email_regexp
|
|
|
|
|
2018-11-26 08:39:32 -05:00
|
|
|
validates :first_name, presence: true
|
|
|
|
validates :last_name, presence: true
|
2018-11-26 11:34:42 -05:00
|
|
|
validates :date_of_birth, presence: true
|
2018-11-28 08:09:23 -05:00
|
|
|
validates :phone_number, presence: true
|
2018-11-28 09:05:58 -05:00
|
|
|
|
2019-03-23 21:42:27 -04:00
|
|
|
validates :account, uniqueness: true
|
2018-12-13 00:36:00 -05:00
|
|
|
|
2019-03-25 20:56:31 -04:00
|
|
|
#############
|
|
|
|
# Callbacks #
|
|
|
|
#############
|
|
|
|
|
2018-11-28 09:05:58 -05:00
|
|
|
before_validation do
|
2018-12-05 21:46:32 -05:00
|
|
|
email&.strip!
|
|
|
|
|
2018-11-28 09:05:58 -05:00
|
|
|
self.middle_name = nil if middle_name.blank?
|
|
|
|
self.occupation = nil if occupation.blank?
|
|
|
|
self.telegram_username = nil if telegram_username.blank?
|
|
|
|
self.organization_membership = nil if organization_membership.blank?
|
|
|
|
self.comment = nil if comment.blank?
|
|
|
|
end
|
2018-11-26 08:39:32 -05:00
|
|
|
end
|