question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Left join query help

See original GitHub issue
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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
koskimascommented, Jan 10, 2020
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).

1reaction
koskimascommented, Jan 17, 2020

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'))
  })
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'))
  })
Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL LEFT JOIN Keyword - W3Schools
The LEFT JOIN keyword returns all records from the left table (table1), and the matching records from the right table (table2). The result...
Read more >
SQL - LEFT JOINS - Tutorialspoint
The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in the right table. This means...
Read more >
SQL LEFT JOIN (With Examples) - Programiz
The SQL LEFT JOIN joins two tables based on a common column, and selects records that have matching values in these columns and...
Read more >
How to perform a LEFT JOIN in SQL Server between two ...
SELECT * FROM (SELECT [UserID] FROM [User]) a LEFT JOIN (SELECT [TailUser], [Weight] FROM [Edge] WHERE [HeadUser] = 5043) b ON a.UserId =...
Read more >
A Comprehensive Guide to LEFT JOIN in SQL
The left join, however, returns all rows from the left table whether or not there is a matching row in the right table....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found