hoyvoy / laravel-cross-database-subqueries

Eloquent cross database compatibility in subqueries
MIT License
103 stars 45 forks source link

Having trouble using whereHas inside whereHas #12

Open buglinjo opened 5 years ago

buglinjo commented 5 years ago

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 commented 5 years ago

up gan

MwSpaceLLC commented 4 years ago

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 :+1:

gfernandez-me commented 4 years ago

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 commented 4 years ago

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