I'm create a Ruby on Rails web application. I have 4 models, which are User, Job, Candidate, ApplyingJob. User is the one who will be using the web application and the user can create Job and Candidate, while the from the Candidate, the candidate will be able to add an ApplyingJob and ApplyingJob will carry the same information from the Job. Below are my associations,
Here's my problem, I want to let the User be able add an ApplyingJob in the Candidate's profile, and that particular ApplyingJob belongs_to that Candidate and also the Job. ApplyingJob carries 2 foreign keys, which are candidate_id and job_id. If the User creates a new ApplyingJob from the Candidate's profile, the ApplyingJob is associated to the Candidate since there is a candidate_id, but how does it associate to the Job because the User creates a new ApplyingJob in the Candidate's profile?
Think you could get rid of the
has_many :candidates and have a
Candidate belong_to a Job? From a quick glance all associations should from then be correct. You could do then
User.first.jobs.first.candidates. The join table would never have to called upon.
Also check if the
has_one :applyingjob is correct.