⚠ 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

Add more column in realation



Alfandi Nurulmukhlis
  • profile picture
  • Member

Posted 30 September 2013 - 04:14 AM

the first, special thaks to Grocerycrud, that's Great and Awesome..!!

sorry for my newbie post and bad english

i have question..

for example :

i have table employees and offices

in user manual, Set a relation :

$crud->display_as('officeCode','Office City');
$crud->set_relation('officeCode','offices','city');

how can i add more field that view not only city, but i need 'phone','state','country', etc in employees table with relation??

so, employees table's view will be like this:
lastname,firstname,extension,email,office city,phone,country,job tittle (text bold relation with office table)

 


davidoster
  • profile picture
  • Member

Posted 30 September 2013 - 06:40 AM

Hello and welcome to the forums [member=alfandi nurulmukhlis].

Well this is a very valid question and I will try to explain it as simple as possible.

 

If we assume that your original table employees has only officeCode and not any more fields to make additional relations, if it is ok proper for your design you can map the addtional information using fields like so,

$crud->set_relation('officeCode', 'offices', '{city} - {phone}, {state}/{country}');

The symbols '-' ',' '/' I have put myself and you can change them to your liking.

Basicaly I am using the 2nd example from the documentation of the set_relation function.

Please make a note that all these will come (relate) from a single record of the offices table into a single field, officeCode for this specific example.

If you need the additional fields (phone, state, country) to be displayed on different columns (fields) then you need to follow another approach but first let us know if this is what you were looking for.


Alfandi Nurulmukhlis
  • profile picture
  • Member

Posted 30 September 2013 - 07:56 AM

thanks for the answer, that's great answer :)

for now, it's enough for my project.. thanks.. :D

thanks for guide me to use user manual and example.. :)