thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.81k stars 2.67k forks source link

server-side search on relationships #5645

Open toto975 opened 2 years ago

toto975 commented 2 years ago

Laravel version

9.7.0

PHP version

8.1.4

Voyager version

1.5

Database

MySQL 8.0.28

Description

Search on relationship with serverside pagination

Steps to reproduce

Model Parcours (id, cadre_id, date) Model Cadre (id, name) In the BREAD, Parcours has relationship belongsTo Cadre and display Cadre name

In the Parcours list view, the column Cadre is sortable. But the search field goes to this error :

SQLSTATE[42S22]: Column not found: 1054 Field 'parcours.parcour_belongsto_cadre_relationship' unknown in where clause
select count(*) as aggregate from `parcours` left join `cadres` as `joined` on `parcours`.`cadre_id` = `joined`.`id` where `parcours`.`parcour_belongsto_cadre_relationship` LIKE %NAME% and `parcours`.`deleted_at` is null

Expected behavior

The SQL Query must be

select count(*) as aggregate fromparcoursleft joincadresasjoinedonparcours.cadre_id=joined.idwherecadre.nameLIKE %NAME% andparcours.deleted_atis null

Screenshots

None of theses fixes work for me : https://github.com/the-control-group/voyager/issues/5635 https://github.com/the-control-group/voyager/issues/5449 https://github.com/the-control-group/voyager/issues/5412 https://github.com/the-control-group/voyager/pull/5312 https://github.com/the-control-group/voyager/pull/5245 https://github.com/the-control-group/voyager/pull/5185 https://github.com/the-control-group/voyager/issues/3595

I put same name for cadre_id and Cadre relationship. I check the cadre_id browse. I uncheck the Cadre browse image The search is OK. But it's the cadre_id which is displayed. image I want the cadre'name

Next I check the Cadre browse image The search is OK, it's the Cadre name which is displayed.

But there is both Cadre in the select dropdown search field, one for cadre_id, the other for Cadre relationship image

Additional context

No response

vikasfreedom commented 8 months ago

Did anyone find exact solution to this ? @Walt2018 your code will only work for specific browse file, what happens if it is showing in all the filters wherever we created a relationships in BREAD ? we can't make custom browse files for each module.

toto975 commented 1 month ago

I confirm this PR https://github.com/thedevdojo/voyager/pull/5754 fixes the bug, in these conditions :