⚠ 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

Show Related table with more fields



asep
  • profile picture
  • Member

Posted 31 October 2017 - 03:38 AM

Hi all,
 
i wanna list my tb_comment
 with structure,
 
tb_comment (id,patient_id,comment,answer)
tb_patient (id,patient_id,hospital_id,patient_name)
tb_hospital (id,hospital_name)
 
all id fields, is PK.
 
how can i wanna do that whe i wanna show fields like :
hospital_name,patient_name,comment,answer
 
 
thanks for your kind answer.
 
 
 

 


Amit Shah
  • profile picture
  • Member

Posted 31 October 2017 - 06:12 AM

Well.. very frankly what i feel this is more like a report rather then a grid / listing for crud that you are looking into..

Reason - there may be 1-1 relation between patient - hospital .. fine with it..

but there will be 1-n relation between patient-comments

that is where the issue can technically come in. 

If u planning to display the list in the comments table (to show the patient name / hospital name) .. rather then creating such complex scenarios - i will recommend u should add hospital_id in the comments table itself so it can be a straight join rather then sub join ..

i know you followed the method of normalization and it might be good as per the rules.. but at times for optimization / speed / performance, the solutions can be a result of denormalization.

 

As of your requirement - it is not possible with the standard flow / implimentation of the system .. ya there is 1 way ..

as for patient - u can do a join ..

and as for hospital - u can add a column hospital and make a callback on column to fetch the relevant hospital for the patient.

 

this is a hack you can surely use .. but aint recommended for optimum results.. hence u may re-think of denormalizing your structure and adding hospital_id in comments table.

 

Happy GCing :)