Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
Precedence and parentheses In Join. How can I write below SQL query in objection ORM?

I have the following SQL query:

select p.id, p.slug, p.post_author, b.id, b.is_deleted  from posts p 
left join blocks b 
on 
    ((b.blocked_id = p.post_author and blocker_id = <user id>)
    or 
    (b.blocked_id = <user_id> and b.blocker_id = p.post_author))
    and b.is_deleted = false
where b.id is null
order by posted_at  desc limit 20

and need a corresponding objection orm statement, and I'm not sure how to bring in those bracket precedence. Below is what I have as a modifier so far:

getUnblockedUsersPosts: (builder) => {
            builder.leftJoin('blocks as b', function(){
              this.on('b.blocked_id', '=', 'posts.post_author')
              .andOn('b.blocker_id', '=', parseInt(user.id))
              .orOn('b.blocked_id', '=', parseInt(user.id))
              .andOn('b.blocker_id', '=', 'posts.post_author')
              .andOn('b.is_deleted', knex.raw('false'))
            }).where('b.id', 'is', null)      
          },
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So above query was solved by the below code, reference: https://knexjs.org/#Builder-join

getUnblockedUsersPosts: (builder) => {
            builder.leftJoin('blocks as b', function(){
              this.on(function(){
                this.on(function(){
                  this.on('b.blocked_id', '=', 'posts.post_author')
                  .andOn('b.blocker_id', '=', parseInt(user.id))
                })
                this.orOn(function(){
                  this.on('b.blocker_id', '=', 'posts.post_author')
                  .andOn('b.blocked_id', '=', parseInt(user.id))
                })
              })
              this.andOn('b.is_deleted', knex.raw('false'))
            }).where('b.id', 'is', null)      
          }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!