post by fede72bari on Jan 19, 2022

I have noted a problem on filtering the view tables by keywords when there is a reference to other tables. The filtering process is not working. Give a look to this screenshot

The reference are defined correctly with these declarations in the controller:

        $this->grocery_crud->set_relation('units_of_measure_id','units_of_measure','{unit_of_measure} ({id})', null, 'unit_of_measure');
        $this->grocery_crud->set_relation('languages_id','languages','{name} - {language_short_key} ({id})', null, 'name');

Reading the log file I found this

Query error: Column 'name' in where clause is ambiguous - Invalid query: SELECT `formats`.*, CONCAT('', COALESCE(j1cfe157f.unit_of_measure, ''), ' (', COALESCE(j1cfe157f.id, ''), ')') as s1cfe157f, CONCAT('', COALESCE(jd21dc9dc.name, ''), ' - ', COALESCE(jd21dc9dc.language_short_key, ''), ' (', COALESCE(jd21dc9dc.id, ''), ')') as sd21dc9dc
FROM `formats`
LEFT JOIN `units_of_measure` as `j1cfe157f` ON `j1cfe157f`.`id` = `formats`.`units_of_measure_id`
LEFT JOIN `languages` as `jd21dc9dc` ON `jd21dc9dc`.`id` = `formats`.`languages_id`
WHERE `name` LIKE '%rectal%' ESCAPE '!'
 LIMIT 10

The problem is clearly on the column “name” since both formats and languages have a column called “name”. The WHERE clause should have been generated preponing the main table name as in ‘formats.name’ . Anaone experienced the same trouble? is it possible to have a fixing? Thanks.

post by mariel_alberto on Jan 19, 2022

Hello
You don’t say you use the same field name
and you tried in the where
this was a quick look

WHERE formats.name LIKE ‘%rectal%’ ESCAPE ‘!’

post by fede72bari on Jan 21, 2022

I do not create the query, GroceryCrud does it for us. Do you mean there are some grocery crud functions I should use or use differently to avoid the problem? Because for sure I cannot change manually the query itself. Thanks.

post by fede72bari on Jan 24, 2022

post by fede72bari on Feb 1, 2022

May I ask to GC guys to give a look to this use case to check if there is a bug in the query creation? Thank you.

post by johnny on Feb 1, 2022

Hello @fede72bari , from what I understood you are referring to Grocery CRUD version 1 right? Are you using the latest version? I remember we had similar issues but are resolved at the latest version (e.g. 1.6.4)

Can you please provide us which version are you using?

Regards
Johnny

1 year later

post by sdss on Feb 3, 2023

Hey, @fede72bari I believe you are referring to Grocery CRUD version 1 at this point. Use the most recent version, please. I recall that these problems have been fixed in the most recent version (e.g. 1.6.5)
Would you kindly let us know what edition you can use? Nowadays many designs of tables are ahead.

1 / 7
Jan 2022