I have Job and Feedback models.
They are associated like this:
Job has_many :feedbacks
Feedback belongs_to :job
I'm trying to make a query to get jobs which have NO feedbacks with feedback.user_id == job.client_id
I have Job and Feedback models.
They are associated like this:
Job has_many :feedbacks
Feedback belongs_to :job
I'm trying to make a query to get jobs which have NO feedbacks with feedback.user_id == job.client_id
jobs=Job.find(:all, :select => 'DISTINCT id', :order=>"id asc").map { |n| n.id.to_s })
feedbacks=Feedback.find(:all, :select => 'DISTINCT job_id', :order=>"job_id asc").map { |n| n.job_id.to_s })
jobs_without_feedbacks=jobs-feedbacks
ok. then try this. it might work good in your case. jobs_without_feedbacks will be the array of ids of the job with no feedback.
jobs=Job.all
no_feedback_jobs=Array.new
jobs.each do |job|{ (no_feedback_jobs<< job) if !job.feedback}
Try this .It will work fine
feedbacks = Feedback.map(&:user_id).uniq
User.includes(:jobs => :feedbacks).where.not(:client_id => feedbacks).where(:id => current_user.id)
Try this
This uses two queries, but the pluck
should be relatively light.
Job.includes(:feedbacks)
.where(feedbacks: {id: nil})
.where.not(client_id: Feedback.pluck(:user_id))