Conversation
…-on-erd-with-tests
…-on-erd-with-tests
…-on-erd-with-tests
…-on-erd-with-tests
| @@ -0,0 +1,32 @@ | |||
| class Application < ApplicationRecord | |||
| belongs_to :job, counter_cache: :applications_count | |||
There was a problem hiding this comment.
why are we using counter_cache here? Can you please explain?
There was a problem hiding this comment.
Hello @hoh-wtag bhai, The counter_cache is a Rails performance optimization feature. Without counter_cache: if we wanted to list out all the applications or total applications count, we had to perform another query on the database. By using counter_cache, we are actually reducing that extra query, this is related to the N+1 Query problem i studied in Rails Docs.
Thanks bhai.
| # | ||
| # It's strongly recommended that you check this file into your version control system. | ||
|
|
||
| ActiveRecord::Schema[8.0].define(version: 2025_09_24_090332) do |
There was a problem hiding this comment.
You have all your migrations in this PR, but how does the changes in schema file exist in the base branch?
There was a problem hiding this comment.
@hoh-wtag bhai, sorry for that. It happened because i pulled the initiate-rails branch here and then mistakenly accepted incoming changes of the schema file in the current branch. that's why it happened.
|
|
||
| # Don't care if the mailer can't send. | ||
| config.action_mailer.raise_delivery_errors = false | ||
| config.action_mailer.raise_delivery_errors = true |
There was a problem hiding this comment.
Can you please explain what's the purpose of changing thos to true?
There was a problem hiding this comment.
Hello @hoh-wtag bhai, I actually set it to true because i wanted the application to raise an error whenever it is failed to send an email. If set to false, the application will silently run without raising any error, however just sending the error in the log.
| belongs_to :job, counter_cache: :applications_count | ||
| belongs_to :user | ||
|
|
||
| enum :status, { applied: 0, viewed: 1, shortlisted: 2, rejected: 3, hired: 4, withdrawn: 5 } |
There was a problem hiding this comment.
validates :status, inclusion: { in: statuses.keys }
Do we need additional validation for enum?
There was a problem hiding this comment.
@hoh-wtag bhai, added the validation. Thank you.
|
|
||
| validates :job_id, uniqueness: { scope: :user_id, message: "You have already applied for this job" } | ||
|
|
||
| has_one_attached :resume |
There was a problem hiding this comment.
can we add validations on the file types of the reswume, so that users cannot upload any kinds of files?
There was a problem hiding this comment.
@hoh-wtag added the validation for resume, Thank you.
| end | ||
|
|
||
| def recommended_jobs | ||
| return [] unless payload["job_ids"].present? |
There was a problem hiding this comment.
use jsonb in the DB and cast it in the model using Rails’ typed attributes
store_accessor :payload, :job_ids
| scope :managers, -> { where(role: :manager) } | ||
| scope :standard, -> { where(role: :standard) } | ||
| scope :primary, -> { where(is_primary: true) } | ||
| scope :pending, -> { where(status: :pending) } | ||
| scope :approved, -> { where(status: :approved) } | ||
| scope :rejected, -> { where(status: :rejected) } |
| has_many :user_skills, dependent: :destroy | ||
| has_many :users, through: :user_skills |
There was a problem hiding this comment.
If we use has_many :users, through: :user_skills do we need has_many :user_skills, dependent: :destroy seperately?
There was a problem hiding this comment.
@hoh-wtag bhai, without dependent: :destroy on user_skills, rails won't auto-delete UserSkill rows. We might end up with a foreign key error blocking deletion if we use DB FKs.
| @@ -0,0 +1,9 @@ | |||
| class UserSkill < ApplicationRecord | |||
| validates :user_id, uniqueness: { scope: :skill_id } | |||
| validates :experience_years, numericality: { greater_than_or_equal_to: 0 } | |||
There was a problem hiding this comment.
| validates :experience_years, numericality: { greater_than_or_equal_to: 0 } | |
| validates :years_of_experience, numericality: { greater_than_or_equal_to: 0 } |
|
|
||
| gem "devise" | ||
| gem "email_validator" | ||
| gem "grape" |
…mmendation model payload
Models, Associations & Database Schema Setup
Trello Ticket: Models, Associations & Database Schema Setup
Description
Created all core database models and their associations based on the ERD. Added validations and unit tests for all models to ensure correctness.
Changes