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

Having trouble using whereHas inside whereHas #12

Open
buglinjo opened this issue Sep 24, 2019 · 4 comments
Open

Having trouble using whereHas inside whereHas #12

buglinjo opened this issue Sep 24, 2019 · 4 comments

Comments

@buglinjo
Copy link
Contributor

buglinjo commented Sep 24, 2019

  • Laravel Cross Database Subqueries Version: 5.6.5
  • PHP Version: 7.3
  • Database Driver & Version: MySQL 8.0

Description:

Is there a way to make queries like ->whereHas('foo', function($q) { $q->whereHas('bar', ... ) }) work?

Steps To Reproduce:

If I do:

Model::whereHas('foo', function ($q) {
    $q->where('column', '=', 'asd');
})->get();

everything works fine, but if I try this:

Model::whereHas('foo', function ($q) {
    $q->whereHas('bar', function ($q) {
         //anything here is still using default connection.
    });
})->get();

it is still using default connection.

@Zuhdannur
Copy link

up gan

@MwSpaceLLC
Copy link

Hi there, we want to write that for us all work fine in mysql with package cross-database.

image

In this query User are in DB1 and categories are in DB2. the result work great!

For us, we must specify relation connection ('database.relation') in :

image

And for User, we must replace Authenticatable with new model class:

image

image

Thanks for the trick 👍

@gfernandez-me
Copy link

gfernandez-me commented Sep 9, 2020

for me, it keeps doing the query in the wrong db

generic model:
pic3
query:
pic2
user model relation (users table on database1, roles and roles_user on database2)
pic1
role model (database2)
pic4

error:

Undefined table: 7 ERROR: relation "roles" does not exist

@gfernandez-me
Copy link

gfernandez-me commented Sep 11, 2020

Forget it, I removed the library and extended belongsToMany, it was easier. This library only was creating problems in other parts

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

4 participants