select account.accts_account_id, user_account.is_fvrt
from account
left join user_account on account.accts_account_id = user_account.accts_account_id and user_account.usr_id='5dfb1475a4c76e0e9a5a9e73'
can somebody help me do this in obection js and also explian how this is done. This query is so simple to build in sql why it is so difficut to figure out in objectionjs
await Account.query()
.select('account.accts_account_id', 'user_account.is_fvrt')
.leftJoin('user_account', join => {
join
.on('account.accts_account_id', 'user_account.accts_account_id')
.onVal('user_account.usr_id', '5dfb1475a4c76e0e9a5a9e73')
})
This query is so simple to build in sql why it is so difficut to figure out in objectionjs
Maybe you are not trying that hard? I don't know how that could be any simpler in objection. And this is literally the second example in the docs (objection's leftJoin documentation links to knex).
can you show me where onVal is documented on knex.com?
You are right, they haven't documented onVal. Here's two other well documented ways to do that query:
await Account.query()
.select('account.accts_account_id', 'user_account.is_fvrt')
.leftJoin('user_account', join => {
join
.on('account.accts_account_id', 'user_account.accts_account_id')
.on('user_account.usr_id', val('5dfb1475a4c76e0e9a5a9e73'))
})
```js
await Account.query()
.select('account.accts_account_id', 'user_account.is_fvrt')
.leftJoin('user_account', join => {
join
.on('account.accts_account_id', 'user_account.accts_account_id')
.on('user_account.usr_id', raw('?', '5dfb1475a4c76e0e9a5a9e73'))
})
ouch. we need to document that.