relationship from another database

Hi guys, i am trying to use SelectFilter as a relationship between 2 entities where each one exists in its own database , so something like mysql_1.companies and mysql_2.tasks i have already set the connections in the models and relationship and everything works fine in select form where i can search and get the data. But when i use select filter it doesn't work where i get the following error
Base table or view not found: 1146 Table 'delivery.companies' doesn't exist (Connection: mysql, SQL: select count(*) as aggregate from `tasks` where (exists (select * from `companies` where `tasks`.`company_id` = `companies`.`id` and `companies`.`id` = 2)))
Base table or view not found: 1146 Table 'delivery.companies' doesn't exist (Connection: mysql, SQL: select count(*) as aggregate from `tasks` where (exists (select * from `companies` where `tasks`.`company_id` = `companies`.`id` and `companies`.`id` = 2)))
i have tried to add the connection name like ->relationship('mysql_1.companies') but it doesn't work neither right now i am doing the following
->query(function (Builder $query , $state){
if ($state['value'] ){
$query->where('company_id', $state);
}
})
->query(function (Builder $query , $state){
if ($state['value'] ){
$query->where('company_id', $state);
}
})
but i am not sure if this is a bug, or is there a specific option in select filter i can enable this. thank you for your help
2 Replies
ChesterS
ChesterS9mo ago
I assume you have relationships set up and they work correctly. You can try something like this (not sure if this will work tbh)
->query((function (Builder $query , $state){
if ($state['value'] ){
$query->whereHas('company', function (Builder $builder) use ($state) {
$builder->where('company_id', $state);
});
}
})
->query((function (Builder $query , $state){
if ($state['value'] ){
$query->whereHas('company', function (Builder $builder) use ($state) {
$builder->where('company_id', $state);
});
}
})
or use a raw query?
->query(function (Builder $query , $state){
if ($state['value'] ){
$query->whereRaw(...);
}
})
->query(function (Builder $query , $state){
if ($state['value'] ){
$query->whereRaw(...);
}
})
Just suggestions though, I don't grok Eloquent 🤷‍♂️
Cybrarist
Cybrarist9mo ago
yea this is what i am doing currently, but it just feels weird since it's natively supported in other places but not in select filter.