adonis join with multi condictions 1

adonis join with multi condictions

...
let posts = await Posts
  .query()
  .leftJoin(‘post_titles’, function () {
    this
    .on(‘post_titles.post_id’, ‘posts.id’)
    .andOn(‘post_titles.lang_code’, Database.raw(’?’, [‘EN’]))
  })
...

Here is what the above code is Doing:
1. We are querying the posts table.
2. We are joining the post_titles table.
3. We are joining the post_titles table on the post_id column of the posts table and the lang_code column of the post_titles table.
4. We are joining the post_titles table on the lang_code column of the post_titles table with the value of the lang_code variable.

Similar Posts