Jump to content


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

setDependentRelation setRelation

  • Please log in to reply
1 reply to this topic

#1 dhyanan73

dhyanan73

    Member

  • Members
  • PipPip
  • 13 posts

Posted 04 October 2019 - 05: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?

 



#2 larasmith

larasmith

    Advanced Member

  • Members
  • PipPipPip
  • 191 posts
  • LocationPhilippines

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.groceryc...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.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users