I'm trying to implement a somewhat complex query with a left join. My
intent is to identify open orders. An order is open if:
* there are no attempts where `accepted` = true
* There are no attempts where `text` is null
* There are no attempts where `text` != null and `accepted` = null
I think I have the query modeled correctly, but now I need a final
"HAVING COUNT(
attempts.id) = 0". I can't for the life of me figure out
how to implement this, though. Could someone please help?
Here's what I have so far:
Order.all({
limit, offset, order: [["updated_at", "DESC"]],
include: [
{
model: Attempt,
where: {
$or: [
{accepted: true},
{text: null},
{
$and: [
{text: {$ne: null}},
{accepted: null}
]
}
]
},
required: false
}
],
group: ["
order.id"],
having: ...
})
Thanks.