php - Laravel Eloquent, multiple schema query -
i have 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 relation_one
, relation_two
relationships fine, need load relationship per row, either relation_three
or relation_four
depending on value of modelone->object
.
the issue having modelone
schema1
, tables used in relation_three
& relation_four
schema2
.
both models set correct individual protected $connection
, protected $table
variables.
the error recieving tables relationship_three
or relationship_four
not exist sub-query checking wrong schema.
can suggest how fix this? have had through docs couldn't find solution.
i suggest separating different databases relations different fields, @ least. way can load both (as suggested in comments) , differentiate logic within controller/model code.
also, guess you'll need define connection name on model level, if not done yet:
class model_two_relation { protected $connection = 'your-database-name-from-config'; }
you might want specify connection within relation join condition:
$q = modelone::with('relation_one', 'relation_two') ->wherehas('relation_three', function ($q) { $q->from('resources.one')->where('object', 'obj1'); }) ->wherehas('relation_four', function ($q) { $q->from('resources.two')->where('object', 'obj2'); }) ->get();
links: http://fideloper.com/laravel-multiple-database-connections
Comments
Post a Comment