⚠ 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

create relation to first table and then create relation from first table to another table



Yovi Pratama
  • profile picture
  • Member

Posted 01 April 2013 - 03:20 AM

Hello every one, i wanna ask you,

 

if i have table A,

how can i create relation to table B, and then create another relation from table B to table C, and then get the value from some field on table C?

for example, i have 3 table,
A (id_A, id_B, description_A)
B (id_B,id_C,description_B )
C(id_C,description_C)

my current table on my method is table A, but i wanna get value from field description_C in table C?

any one can help?


davidoster
  • profile picture
  • Member

Posted 01 April 2013 - 08:36 AM

These set_relation functions need to be on different controller functions since you have one (1) set_table!

Unless you make more than one new grocery_CRUD()!

 

For A

set_table('a');

set_relation('id_B', 'b', 'id_B');

(similar for table a )

 

If you want to have multiple tables:

 

cruda = new grocery_CRUD();

cruda->set_table('a');

cruda->set_relation('id_B', 'b', '{id_B} - {description_B}');

 

 

crudb = new grocery_CRUD();

crudb->set_table('b');

crudb->set_relation('id_C', 'c', '{id_C}  - {description_C}');

 
If the above is not very convenient then you need to make your own model.
 
Depending on where you want to use description_C you get the field value using the appropriate method.
If you want the value (of description_C) while in server(e.g. you want to use it on a controller function) then just make a model that parses this data.
If you want the value on client side then you need to make some javascript call.