28 lines
814 B
Ruby
28 lines
814 B
Ruby
class Worker < ApplicationRecord
|
|
# One-to-many relationship with Employments
|
|
has_many :employments
|
|
|
|
# Many-to-many relationship with Participants through Employments
|
|
has_many :participants, through: :employments
|
|
|
|
# Many-to-many relationship with Employers through Participants
|
|
has_many :employers, through: :participants, source: :employer
|
|
has_many :employer_records, through: :participants
|
|
|
|
has_many :onboarding_items, as: :owner
|
|
accepts_nested_attributes_for :onboarding_items
|
|
|
|
# Validations
|
|
validates :first_name, presence: true
|
|
validates :last_name, presence: true
|
|
validates :ssn, uniqueness: true, allow_blank: true, presence: true
|
|
|
|
# Method to return the full name of the worker
|
|
def full_name
|
|
"#{first_name} #{last_name}"
|
|
end
|
|
|
|
has_many :bank_accounts, as: :owner
|
|
|
|
end
|