40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class MembershipApp < ApplicationRecord
|
|
################
|
|
# Associations #
|
|
################
|
|
|
|
belongs_to :account, inverse_of: :own_membership_app
|
|
belongs_to :country_state, optional: true
|
|
|
|
has_one :regional_office, through: :country_state
|
|
has_one :person, through: :account, inverse_of: :own_membership_app
|
|
|
|
###############
|
|
# Validations #
|
|
###############
|
|
|
|
validates :email, presence: true, format: Devise.email_regexp
|
|
|
|
validates :first_name, presence: true
|
|
validates :last_name, presence: true
|
|
validates :date_of_birth, presence: true
|
|
validates :phone_number, presence: true
|
|
|
|
validates :account, uniqueness: true
|
|
|
|
#############
|
|
# Callbacks #
|
|
#############
|
|
|
|
before_validation do
|
|
email&.strip!
|
|
|
|
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
|
|
end
|