I have been trying to filter the users who applied for X job offer, but to have a better overview I will explain my association and my problem:
class Job < ApplicationRecord
belongs_to :enterprise
has_many :job_candidates
end
class JobCandidate < ApplicationRecord
belongs_to :job
belongs_to :user
end
class User < ApplicationRecord
has_many :job_candidates
end
class User < ApplicationRecord
has_many :jobs
end
I have users (User)
who apply for jobs (Job)
that companies (Enterprise)
publish, for this at the time when user X applies to X employment, within the table (JobCandidate)
is stored , who applied to the offer (user_id)
, since work is postulated (job_id)
, only those 2 fields, now well, therefore JobCandidate
is related to the models User and Job, now well within the Enterprise dashboard I need print all those records of JobCandidate
where their relation job_candidate.user.enterprise.id
matches the current user, however the first idea that came to me was to make a scope, but apparently within the scope of the model I can not compare it with a current session is say (current_enterprise)
, therefore the controller comes to mind, but I can not filter that data, something that would be like:
def dashboard
@job_candidates = JobCandidate.all.where(job_candidate.job.enterprise_id: current_enterprise.id)
end
This is an idea that is rather vague, because I can not arrive at an exact way of comparing the id of the companies of the jobs to which (job.enterprise.id)
were nominated with the current company session (current_enterprise)
, the idea is to filter both the jobs and the users who the company will see who applied for their jobs
I do not know if I've managed to make myself understood, but I'll be very grateful if you can give me a better idea, regards!