Files
baclight/app/models/member.rb
T

36 lines
1.1 KiB
Ruby
Raw Normal View History

class Member < ApplicationRecord
2026-04-15 08:12:47 -04:00
include MemberAutomation
2026-03-19 00:42:27 -04:00
belongs_to :id_card_plan, class_name: 'IdCard::Plan', optional: true
belongs_to :employer
2026-04-15 08:12:47 -04:00
serialize :dependents, coder: JSON
2026-05-06 13:28:16 -04:00
validates :pb_entity_key, presence: true
validates :name, :family_id, :mb_member_key, :pl_plan_key,
:id_card_display_name, presence: true, unless: :new_record?
validates :division, presence: true, if: -> { employer.id_card_setup.has_divisions }
2026-06-17 23:23:36 -04:00
# validates :coverage_class, :dental_plan_key, presence: true, if: -> { employer.id_card_setup.has_dental }
validates :mb_member_key, :pb_entity_key, uniqueness: true
validates :name, uniqueness: { scope: :employer_id }
2026-05-06 13:28:16 -04:00
2026-04-15 08:12:47 -04:00
before_validation :format_dependents, if: :dependents_changed?
2026-03-27 08:04:37 -04:00
def id_card_field_exception_values
address = Vhcs::PbEntityAddress.find_by(pb_entity_key: self.pb_entity_key)
{
zipcode: address.zip,
state: address.state,
family_id: self.family_id
}
end
2026-04-15 08:12:47 -04:00
private
def format_dependents
if self.dependents.is_a?(String)
self.dependents = self.dependents.split(",").map(&:strip)
end
end
end