Rails associations
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,
User
has_many :candidates
has_many :jobs
Job
belongs_to :user
has_many :applyingjobs
Candidate
belongs_to :user
has_one :applyingjob
ApplyingJob
belongs_to :candidate
belongs_to :job
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?
@geometry dash
Excellent advice that is easy to understand. This will undoubtedly come in handy when the time comes for me to launch my blog.