⚠ 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

[REQ] setDependentRelation: allow multiple dependent relations for the same relation



dhyanan73
  • profile picture
  • Member

Posted 04 October 2019 - 17:15 PM

Hi to all,

currently setDependentRelation does not allow you to set two dependent relations with the same table (the filter table).

In the exlample below two different tables (shops and price_lists), related to orders table, in their respective dependent relations shares the same filter table (retailers, obviously also related with orders table). But only last setted dependent relationship works correctly.

@web-johnny can you solve this problem in one of the next releases, please? I think the case shown in the example below is very common so this functionality would be useful to many.


Database tables for this example:


Table "orders"
-------------------
pk_order
fk_order_retailer
fk_order_shop
fk_order_price_list
...

Table "retailers"
-------------------
pk_retailer
retailer_name
...

Table "shops"
-------------------
pk_shop
fk_shop_retailer
shop_name
...

Table "price_lists"
-------------------
pk_price_list
fk_price_list_retailer
price_list_name
...

Code in orders controller:

...
$crud->setRelation('fk_order_retailer', 'retailers', 'retailer_name');
$crud->setRelation('fk_order_shop', 'shops', 'shop_name');
$crud->setRelation('fk_order_price_list', 'price_lists', 'price_list_name');
$crud->setDependentRelation('fk_order_shop', 'fk_order_retailer', 'fk_shop_retailer'); // this currently doesn't work
$crud->setDependentRelation('fk_order_price_list', 'fk_order_retailer', 'fk_price_list_retailer');
...

 

Until the setDependentRelation function is upgraded as required, can someone suggest a work around to get the same result?

 


larasmith
  • profile picture
  • Member

Posted 07 October 2019 - 02:34 AM

Hi to all,

currently setDependentRelation does not allow you to set two dependent relations with the same table (the filter table).

In the exlample below two different tables (shops and price_lists), related to orders table, in their respective dependent relations shares the same filter table (retailers, obviously also related with orders table). But only last setted dependent relationship works correctly.

@web-johnny can you solve this problem in one of the next releases, please? I think the case shown in the example below is very common so this functionality would be useful to many.


Database tables for this example:


Table "orders"
-------------------
pk_order
fk_order_retailer
fk_order_shop
fk_order_price_list
...

Table "retailers"
-------------------
pk_retailer
retailer_name
...

Table "shops"
-------------------
pk_shop
fk_shop_retailer
shop_name
...

Table "price_lists"
-------------------
pk_price_list
fk_price_list_retailer
price_list_name
...

Code in orders controller:

...
$crud->setRelation('fk_order_retailer', 'retailers', 'retailer_name');
$crud->setRelation('fk_order_shop', 'shops', 'shop_name');
$crud->setRelation('fk_order_price_list', 'price_lists', 'price_list_name');
$crud->setDependentRelation('fk_order_shop', 'fk_order_retailer', 'fk_shop_retailer'); // this currently doesn't work
$crud->setDependentRelation('fk_order_price_list', 'fk_order_retailer', 'fk_price_list_retailer');
...

Until the setDependentRelation function is upgraded as required, can someone suggest a work around to get the same result?

 

It will be a bit lengthy coding but you can achieve what you want. You can instead of setRelation use the fieldType and more specifically the fieldType "dropdown_search". The data of the "dropdown_search" would be from your custom query from the same table. For more you can check the documentation here: https://www.grocerycrud.com/enterprise/api-and-function-list/fieldType/#dropdown_search . You can basically get the dropdown data from the same table as you desired. Customize the query's where condition based on the prior drop-downs value via jquery.