I need to write this mysql query with Objection.js but i can't figure it out how to properly write it.
Here's the query (1276 is an example of an id in people table):
SELECT MAX(c1.price) AS price
FROM computers c1
WHERE c1.ownerId = 1276 AND NOT EXISTS (
SELECT c2.screenSize
FROM computers c2
WHERE c2.ownerId = 1276 AND c2.screenSize > c1.screenSize
)
I have already fetched an instance of person, now i want to do something like:
person.$relatedQuery("computers", db)
.select(db.max(db.ref("price")))
.whereNotExists(qb => qb.where(....
Any suggestion would be really appreciated!