⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Problem



Balanso
  • profile picture
  • Member

Posted 17 July 2019 - 06:19 AM

Hello, i use enterprise version and have error on local server
 
$crud->setTable('aparts', 'owners');
$crud->setSubject('Апартамент', 'Апартаменты');
$crud->columns(['name', 'address', 'owner_id', 'wifi_name', 'wifi_pass', 'price', 'pms_id']);
$crud->displayAs('name','Название');
$crud->displayAs('address','Адрес');
$crud->displayAs('wifi_name','WiFi сеть');
$crud->displayAs('wifi_pass','WiFi пароль');
$crud->displayAs('price','Тариф');
$crud->displayAs('pms_id','Exa ID');
$crud->displayAs('owner_id','Собственник');
$crud->defaultOrdering('aparts.id', 'desc');
$crud->setRelation('owner_id', 'owners', 'name');
 
[2019-07-17 09:14:27] router.ERROR: Uncaught Exception PDOException: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owners.name' in 'order clause'" at C:\OSPanel\domains\dev-aircheckin.ru\lib\vendor\grocery_crud\zendframework\zend-db\src\Adapter\Driver\Pdo\Connection.php line 361 {"exception":"[object] (PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owners.name' in 'order clause' at C:\\OSPanel\\domains\\dev-aircheckin.ru\\lib\\vendor\\grocery_crud\\zendframework\\zend-db\\src\\Adapter\\Driver\\Pdo\\Connection.php:361)"} []
 
But on production server has no errors, it works correctly.
 
I'm print $sql in vendor\grocery_crud\zendframework\zend-db\src\Adapter\Driver\Pdo\Connection.php line 361
 
and on dev server query looks like:
SELECT `owners`.* FROM `owners` ORDER BY `name` ASC;
SELECT `aparts`.`id` AS `id`, `aparts`.`name` AS `name`, `aparts`.`wifi_name` AS `wifi_name`, `aparts`.`wifi_pass` AS `wifi_pass`, `aparts`.`price` AS `price`, `aparts`.`pms_id` AS `pms_id`, `aparts`.`owner_id` AS `owner_id`, `aparts`.`address` AS `address` FROM `aparts` LEFT JOIN `owners` AS `o` ON `aparts`.`owner_id` = `o`.`id` ORDER BY `owners`.`name` DESC LIMIT 10 OFFSET 0;
(THIS IS NOT WORK)
 
error on bold text, if i change that to ORDER BY `o`.`name` it works.
 
on production server sql looks like 
SELECT `owners`.* FROM `owners` ORDER BY `name` ASC;
SELECT `aparts`.`id` AS `id`, `aparts`.`name` AS `name`, `aparts`.`address` AS `address`, `aparts`.`owner_id` AS `owner_id`, `aparts`.`wifi_name` AS `wifi_name`, `aparts`.`wifi_pass` AS `wifi_pass`, `aparts`.`price` AS `price`, `aparts`.`pms_id` AS `pms_id` FROM `aparts` LIMIT 10 OFFSET 0;
SELECT COUNT(*) AS `num` FROM `aparts`;
SELECT `owners`.* FROM `owners` ORDER BY `name` ASC;
 
(IT WORKS!) it's not has `owners` before `name`
 
Meanwhile I use that...
// Not works on local dev server :(
if (MODE != 'dev') {
  $crud->setRelation('owner_id', 'owners', 'name');
}
 

 

 

Please help me, databases data and structure on dev and prod servers is same.

 

 

 


Balanso
  • profile picture
  • Member

Posted 17 July 2019 - 08:19 AM

I'm changed $crud->setTable('aparts', 'owners');

to $crud->setTable('aparts');

the mistake still remained


dbarros
  • profile picture
  • Member

Posted 12 September 2019 - 13:07 PM

 

@Balanso,

 

Not sure if your issue is the same as mine, however i was receiving a similar error when using setRelation, the thing that I did to fix was to change the order by in the grid itself to a different column, Let me explain, before I added the "setRelation" I sorted the grid by user_id, so that was the column that the grid was ordering by, then after i added the "setRelation" for  the users table i started to see  the error about the unknown column.

 

setRelation fields if you noticed  are not sortable [sharedmedia=core:attachments:1379]

, hopefully this helps