⚠ 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

Problem with set_relation



joseextremo

joseextremo
  • profile picture
  • Member

Posted 08 February 2018 - 19:44 PM

Hi, in first tiem, sorry for my english hehe.

 

I have a poblem with the function set_relations, i need show a client table and a table for user, pass and rol for the clients, they are two relation tables (clientes and claves), this is my code:

$crud = new grocery_CRUD();
 
$crud->set_table('clientes');
$crud->set_subject('Clientes');
$crud->set_relation('id', 'claves', '{usuario} {rol}');

$output = $crud->render();

The problem is that the code only show de columns of clientes, but not show the columns 'usuario' and 'rol'.

 

Please help me. Thank you very much.

 


joseextremo

joseextremo
  • profile picture
  • Member

Posted 16 February 2018 - 08:23 AM

¿¿???


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 February 2018 - 03:40 AM

Well - the relation what you are trying to achieve is more like parent to child.. rather the relations are the other way round - looked up .. where i have the key to the parent record. 

 

And it will show values only for the records that match its matching key with the primary key of the other table (expecting master). 

 

What here if i am not mistakened - you trying to hook up to is like a parent key (from clients) to claves - having client_id as referring key to the client master entry. And it have its own primary key that is separate from the client_id - 

how this works - GC library is going to look into the table (claves) and try to find the value for matching key (in your case ID from clients table) with the value in its primary key (That may be other ID - which dose not exists yet .. or something).

The join applied in here is left join ..That is the reason it is not showing you the entries from claves.. as it didnt match any value against its primary key.

 

A solution for you to display the value in listing - do a column callback.

 

Happy GCing :)


slametriady

slametriady
  • profile picture
  • Member

Posted 25 October 2018 - 08:48 AM

Hi, in first tiem, sorry for my english hehe.

 

I have a poblem with the function set_relations, i need show a client table and a table for user, pass and rol for the clients, they are two relation tables (clientes and claves), this is my code:

$crud = new grocery_CRUD();
 
$crud->set_table('clientes');
$crud->set_subject('Clientes');
$crud->set_relation('id', 'claves', '{usuario} {rol}');

$output = $crud->render();

The problem is that the code only show de columns of clientes, but not show the columns 'usuario' and 'rol'.

 

Please help me. Thank you very much.

 

$crud->set_primary_key('id','claves');
 
put primary id table clientes have relation in table claves.
 
I just experienced the same thing