Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

whereExists example from docs not working #331

Open
MZanggl opened this issue Dec 28, 2018 · 1 comment
Open

whereExists example from docs not working #331

MZanggl opened this issue Dec 28, 2018 · 1 comment

Comments

@MZanggl
Copy link

MZanggl commented Dec 28, 2018

https://adonisjs.com/docs/4.1/query-builder#_whereexists
The example for whereExists goes like this

await Database.from('users').whereExists(function () {
  this.from('accounts').where('users.id', 'accounts.user_id')
})

But this has the following output

select * from `users` where exists (select * from `accounts` where `users`.`id` = 'accounts.user_id')

As you can see, it puts single quotes around accounts.user_id so it looks for records where users.id is literally accounts.user_id.

If you look at Laravel's whereExists example they actually use a whereRaw here. https://laravel.com/docs/5.7/queries

But personally I think whereColumn would be even better. It seems that Adonis does not support this method though.

Same problem applies to the whereNotExists example.

@lukaszflorczak
Copy link

The working example should looks like this:

await Database.from('users').whereExists(function () {
      this.from('accounts').whereRaw('users.id = accounts.user_id')
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants