⚠ 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

Implementing 1-1 relation ???



rostamiani

rostamiani
  • profile picture
  • Member

Posted 17 April 2016 - 14:26 PM

Hi

 

I really need to implement 1-1 relation between two tables. These are my tables:

 

Users: id, username, email, password

Userinfo: id, Isers_id, firstname ,lastname, mobile, address, ...

 

The users table is read only... This is a suggested solution:

->set_table('Userinfo')
->columns('users_id','users_id');

->set_relation('users_id','Users','username')
->set_relation('users_id','Users','email')
 

But the problem is that I cannot set two 'users_id' columns!!!

 

What do you suggest?

 

Thanks

 


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 03 May 2016 - 16:04 PM

U cant implement 1-1 relation with crud by default. But u can create after insert_after/update_after function for u purposes


JimRustler

JimRustler
  • profile picture
  • Member

Posted 03 May 2016 - 23:15 PM

I had this issue before, i solved it using views, and replacing the add, edit, read links to the original table controller methods.

 

When using views instead of tables you need to add $crud->set_primary_key("your_view_primary_key_of_table");


mckaygerhard

mckaygerhard
  • profile picture
  • Member

Posted 05 October 2016 - 20:35 PM

using views?

 

how can i set views, there any example.. i have id_data and des_data, when i set the relation only one of those can be show as a column..

 

ehre:

    $this->load->library('grocery_CRUD');
    $crud = new grocery_CRUD();
    $crud->set_table('tablebase');
	$crud->set_relation('id_data','data','{des_data})');
	$output = $crud->render();

the results are that the column id_data does not show, and only show the values of des_data column!

 

i want to show also the id_data column but by separate! how?