obdev/app/models/worker.rb

22 lines
680 B
Ruby
Raw Normal View History

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
# 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
end