I have a tables for jobs and bids. Each job has many bids. There is a bid column "is_selected" that is a boolean. Only one bid can be is_selected=true for a job.
My question is that I want to return the number of jobs where all bids are is_selected=false.
So for example,
Job 1 has bids a=true, b=false, c=false, d=false
Job 2 has bids a=false, b=false, c=false
Job 3 has bids a=false, b=false
Job 4 has no bids
The result of this query should return a query with 3 jobs (only Job 1 has selected a bidder; so it should return job 2, 3, 4).
How can this be done in postgresql or ActiveRecord/Rails?
Update with data structure:
3 tables
Event (has_many jobs)
Job (has_many bids, belongs_to event)
- event_id (integer)
Bid (belongs_to job)
job_id (integer)
is_selected (Boolean)