vendredi 28 juillet 2017

Laravel Eloquent, multiple schema query

I have the below query (simplified):

$q = ModelOne::with('relation_one', 'relation_two')
    ->whereHas('relation_three', function ($q) {
        $q->where('object', 'Obj1');
    })
    ->whereHas('relation_four', function ($q) {
        $q->where('object', 'Obj2');
    })
    ->get();`

It loads the relation_one and relation_two relationships fine, I also need to load another relationship per row, either relation_three or relation_four depending on the value of ModelOne->object.

The issue I am having is that ModelOne is from schema1 and the tables used in relation_three & relation_four are from schema2.

Both models are set up correct with their individual protected $connection and protected $table variables.

The error I am recieving is that the tables for relationship_three or relationship_four does not exist as the sub-query is checking the wrong schema.

Can anyone suggest how to fix this? Have had a look through the docs but couldn't find a solution.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tJ0KNL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire