⚠ 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

setDependantRelationt



egsolis
  • profile picture
  • Member

Posted 03 July 2020 - 02:40 AM

Hi!

 

I have used groceryCrudComunity for a system that's corrently un production, to solve some necesities I use a library called ajax_grocerycrud,  just to get a dependency issue solved:

 

              
  $crud->set_relation('ruta_ruta_id','ruta','{ruta}');  

                $crud->set_primary_key('empresa_id', 'v_cliente_ruta');
                $crud->set_relation('clientes_cliente_id','v_cliente_ruta','empresa');
                $crud->set_relation_dependency('clientes_cliente_id','ruta_ruta_id','ruta_id');   

                                            
                $crud->set_primary_key('empresa_id', 'v_proveedor_ruta');
                $crud->set_relation('proveedor_proveedor_id','v_proveedor_ruta','empresa');                                
                $crud->set_relation_dependency('proveedor_proveedor_id','ruta_ruta_id','ruta_id');            
            
                      
                $crud->set_primary_key('patio_id', 'v_patio_ruta');
                $crud->set_relation('patio_toma','v_patio_ruta','{patio}');
                $crud->set_relation_dependency('patio_toma','ruta_ruta_id','ruta_id');

There I have 3 dependecies and as you can see I use views, not tables.

 

Now that the dependency functionality is available in enterprise edition I'm  working in the migration of the entire system and this dependency looks now like this

 

 

$crud->setRelation('ruta_ruta_id','ruta','{ruta}');  

$crud->setPrimaryKey('empresa_id', 'v_cliente_ruta');
$crud->setRelation('clientes_cliente_id','v_cliente_ruta','empresa');+
$crud->setDependentRelation('clientes_cliente_id','ruta_ruta_id','ruta_id');
  
 
$crud->setPrimaryKey('empresa_id', 'v_proveedor_ruta');
$crud->setRelation('proveedor_proveedor_id','v_proveedor_ruta','empresa'); 
$crud->setDependentRelation('proveedor_proveedor_id','ruta_ruta_id','ruta_id');  

$crud->setPrimaryKey('patio_id', 'v_patio_ruta'); 
$crud->setRelation('patio_toma','v_patio_ruta','patio');
$crud->setDependentRelation('patio_toma','ruta_ruta_id','ruta_id');

 

 

 

But it is not working , when i'm adding a new  item, as soon as I select the first data dependecy   I get an error of  JSON malformed

 

This is the extract that I got

 


</div>{"total_count":14,"items":[{"id":null,"title":"Altamira"},{"id":null,"title":"Altamira Terminal Portuaria, S.A. de C.V."},{"id":null,"title":"Cooper T. Smith de M?xico, S.A. de C.V. (CTS)"},{"id":null,"title":"Industrias Negromex"},{"id":null,"title":"Infraestructura Portuaria Mexicana S.A. de C."},{"id":null,"title":"Inmobiliaria Portuaria De Altamira S.A. de C."},{"id":null,"title":"Operadora de Terminales Maritimas S.A. de C.V"},{"id":null,"title":"Terminal de LNG de Altamira S. de R.L. de C.V"},{"id":null,"title":"Terminal J. Ray McDermott de M?xico, S.A. de "},{"id":null,"title":"Terminal Maritima de BASF"},{"id":null,"title":"Terminal Maritima de de Altamira, S.A. de C.V"},{"id":null,"title":"Terminal Petroquimica de Altamira, S.A. de C."},{"id":null,"title":"TMM LOGISTICS ATM"},{"id":null,"title":"Vopak Terminals Mexico, S.A. de C.V."}]}

 

I can see that "id" for all the data is null. Is that a bug? Could you recomend something?

 

thanks in advance.


egsolis
  • profile picture
  • Member

Posted 06 July 2020 - 02:10 AM

I try changing

 

return [
            'adapter' => [
                'driver' => 'Pdo_mysql',
                'host'     => $db['default']['hostname'],
                'database' => $db['default']['database'],
                'username' => $db['default']['username'],
                'password' => $db['default']['password'],
                'charset' => 'utf8'
            ]

 

to

 

 

return [
            'adapter' => [
                'driver' => 'mysqli',
                'host'     => $db['default']['hostname'],
                'database' => $db['default']['database'],
                'username' => $db['default']['username'],
                'password' => $db['default']['password'],
                'charset' => 'utf8'
            ]

 

Still got the same error. Any Ideas I could try, please?

 

regards.


egsolis
  • profile picture
  • Member

Posted 07 July 2020 - 16:31 PM

I could reproduce the error with the example in the online documentacion:

 

 

https://www.grocerycrud.com/enterprise/api-and-function-list/set-dependent-relation/

 

 

I replaced the table cities with a view of the table of itself  v_view

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_cities`  AS  select `cities`.`id` AS `id`,`cities`.`name` AS `name`,`cities`.`country` AS `country` from `cities` where 1 ;

The code now looks like  this

 

 

public function relation()
{


$crud = $this->_getGroceryCrudEnterprise();
$crud->setTable('customers_db');
$crud->setSubject('Customer', 'Customers');


$crud->displayAs('continent_id', 'Continent');
$crud->displayAs('country_id', 'Country');
$crud->displayAs('city_id', 'City'); 


$crud->setRelation('continent_id','continents','name');
$crud->setRelation('country_id','countries','name');


$crud->setPrimaryKey('id', 'v_cities');
$crud->setRelation('city_id','v_cities','name');


$crud->setDependentRelation('country_id','continent_id','continent_code');
$crud->setDependentRelation('city_id','country_id','country');


$output = $crud->render();
$this->_example_output($output);
}

 

The error:

 

 

 

A PHP Error was encountered

Severity: Notice

Message: Undefined index:

Filename: Core/Model.php

Line Number: 271

Backtrace:

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\Model.php
Line: 271
Function: _error_handler

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\StateAbstract.php
Line: 1073
Function: getRelationData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\DependedRelationState.php
Line: 57
Function: getRelationalData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\GroceryCrud.php
Line: 2433
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\application\controllers\Examples.php
Line: 77
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined index:

Filename: Core/Model.php

Line Number: 271

Backtrace:

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\Model.php
Line: 271
Function: _error_handler

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\StateAbstract.php
Line: 1073
Function: getRelationData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\DependedRelationState.php
Line: 57
Function: getRelationalData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\GroceryCrud.php
Line: 2433
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\application\controllers\Examples.php
Line: 77
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined index:

Filename: Core/Model.php

Line Number: 271

Backtrace:

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\Model.php
Line: 271
Function: _error_handler

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\StateAbstract.php
Line: 1073
Function: getRelationData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\DependedRelationState.php
Line: 57
Function: getRelationalData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\GroceryCrud.php
Line: 2433
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\application\controllers\Examples.php
Line: 77
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined index:

Filename: Core/Model.php

Line Number: 271

Backtrace:

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\Model.php
Line: 271
Function: _error_handler

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\StateAbstract.php
Line: 1073
Function: getRelationData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\State\DependedRelationState.php
Line: 57
Function: getRelationalData

File: C:\xampp2\htdocs\grocery-crud-test\application\libraries\GroceryCrudEnterprise\grocerycrud\enterprise\src\GroceryCrud\Core\GroceryCrud.php
Line: 2433
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\application\controllers\Examples.php
Line: 77
Function: render

File: C:\xampp2\htdocs\grocery-crud-test\index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp2\htdocs\grocery-crud-test\system\core\Exceptions.php:271)

Filename: controllers/Examples.php

Line Number: 26

Backtrace:

File: C:\xampp2\htdocs\grocery-crud-test\application\controllers\Examples.php
Line: 26
Function: header

File: C:\xampp2\htdocs\grocery-crud-test\application\controllers\Examples.php
Line: 78
Function: _example_output

File: C:\xampp2\htdocs\grocery-crud-test\index.php
Line: 315
Function: require_once

{"total_count":4,"items":[{"id":null,"title":"Lyon"},{"id":null,"title":"Marseille"},{"id":null,"title":"Paris"},{"id":null,"title":"Toulouse"}]}