3 things:
- Logistic has_many
RentalRequests through
Type_Logistic association table.
- Logistic does not have to have a RentalRequest to exist (i.e., there's no Type_Logistic association present)
- RentalRequest has a status_id
column
I would like to find all the Logistic records where EITHER there are no associated RentalRequests OR the associated RentalRequest has a status_id
of nil. My current solution is multi-step:
assoc_RR_has_nil_status = Logistic.includes(:rental_requests).where(rental_requests: {status_id: nil}).pluck(:id)
no_assoc_RR = Logistic.includes(:rental_requests).where(rental_requests: {id:nil}).pluck(:id)
inc_logistics_ids = assoc_RR_has_nil_status | no_assoc_RR
@Incomplete_logistics = Logistic.find(inc_logistics_ids.sort)
But I'm wondering if there's a way to do this in one single where
or chain of wheres.
Thanks!
EDIT! Updated my code above because the original merge
represents an AND not an OR.