What do I want
What I need to get all orders without acceptance for a given user, but I'm having issues with the first part only.
What do I have
Here are my models
class Order < ApplicationRecord
has_one :acceptance
end
class Acceptance < ApplicationRecord
belongs_to :order
end
What have I tried
I have already checked this answers
- Rails 4 scope to find parents with no children
- Finding records with no associated records in rails 3
But they applied for a has_many - belongs to scenario (which is, presumably, why they fail). My scenario is simpler: has_one - belongs_to.
So far (after trying by myself, and reading other SO questions) the following have failed.
Order.includes(:acceptance).where(acceptance: { id: nil})
Order.left_outer_joins(:acceptance).where(acceptance: { id: nil })
Order.joins(:acceptance).merge(Acceptance.where(order_id: nil, id: nil))
Moreover, I can't do Order.joins(:acceptance)
because that immediately fetches orders
with an acceptance
associated, I want the opposite of that.
Didn't seem that hard a priori, but it's giving a mild pain.