Stepan Parunashvili
Stepan Parunashvili

Reputation: 2845

The Database Structure for a Recruiting system

I'm a bit of a noob, and wanted to confirm with you guys if I'm on the right track, in regard to modelling an Job recruiting application.

There are users

Each user fills out details, and records 1 video.

There are jobs.

Each job has 1 or 2 specific questions about the job. Users apply to jobs by filling in the 1 or 2 specific questions.

Based on this,

we'll have the User Model.

The User model will have the attributes name, email, degree, pref_city etc, video_id

The user has_many jobs

Then, there's the Job Model. jobs belong_to users

I'm about a confused as to how this model will play out

each job will have job_title, job_desc, salary, etc, as well as custom_question1, custom_question2.

When admin creates the job, they will write custom questions for 1 and 2.

Then, when a user applies to the job, they would answer those questions. However, where would I record the answers to the custom questions?

Am I on the right track?

Upvotes: 0

Views: 399

Answers (4)

Yosep Kim
Yosep Kim

Reputation: 2951

I think you are on the right track. Below code set should give you some idea. Sounds like an awesome project. Have fun!

# user.rb
class User < ActiveRecord::Base
  has_many :jobs # jobs this user posted
  has_many :job_applications
  has_many :user_answers

# job.rb
class Job < ActiveRecord::Base
  has_many :questions
  has_many :job_applications

# question.rb
class Question < ActiveRecord::Base
  has_many user_answers
  belongs_to :job  

# job_application.rb
class JobApplication < ActiveRecord::Base
  belongs_to :user
  belongs_to :job

# user_answer.rb
class UserAnswer < ActiveRecord::Base
  belongs_to :user
  belongs_to :question
  # has a column "answer text..."

Upvotes: 1

Akash
Akash

Reputation: 5221

These is a many to one relationship between jobs and users. User can apply to many jobs and jobs can have many applications; right? You can use the following structure for a more robust model:

User
  has_many :jobs, through: :applications

Job
  has_many :users, through :applications
  has_many :questions

Application
  belongs_to :user
  belongs_to :job
  has_many :answers

Question
  belongs_to :job
  has_one :answer

Answer
  belongs_to :application
  belongs_to :question

I really think instead of linking answers to a user, they should be linked to applications.

Upvotes: 1

Kaleidoscope
Kaleidoscope

Reputation: 3627

http://bit.ly/1giMQIl

It would help to know more about your project. I went the safe route and assumed a couple things:

  • The questions on applications can change
  • You want to remember user answers if those questions changed

Upvotes: 1

trh
trh

Reputation: 7339

Personally I would break the questions and answers away from the job itself in order to have more rails magic, because we do love our meta.

So it would look more like this:

User
  has_many :jobs
Job
  belongs_to :user
  has_many :questions
  has_many :applications
Application
  belongs_to :user
  belongs_to :job
Question
  has_many :answers
  belongs_to :job
Answer
  belongs_to :question
  belongs_to :user

This way you can always do get a list of current answers for a given job by saying

@job.questions.first.answers

Upvotes: 2

Related Questions