Can't figure out `having` clauses

36 views
Skip to first unread message

Nolan Darilek

unread,
Jun 20, 2017, 4:37:01 PM6/20/17
to sequ...@googlegroups.com
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.

Nolan Darilek

unread,
Jul 27, 2017, 1:40:26 PM7/27/17
to sequ...@googlegroups.com
Wanted to bump this post. Any tips? I've looked at the docs and code,
and it isn't obvious how to structure the `having:` option in the ways
I've described.


Thanks.
Reply all
Reply to author
Forward
0 new messages