⚠ 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

auto populate a column in another table



Ahmed Adebiyi Oladapo
  • profile picture
  • Member

Posted 09 September 2016 - 02:21 AM

I have 2 tables i.e Parent and Child. In Parent Table I have Primary Key which is also a Foreign Key in the Child Table.
How can i add new record(s) into the Child table so that the parent ID (Foreign Key) column is automatically populated and linked to a specific parent in the parent table.

 


Athar
  • profile picture
  • Member

Posted 17 January 2017 - 14:46 PM

Use Triggers


hurtz
  • profile picture
  • Member

Posted 17 January 2017 - 15:53 PM

@athar - can you please give an example on how to do this in CI?


Athar
  • profile picture
  • Member

Posted 17 January 2017 - 17:16 PM

What you want is not a difficult at all if you study grocery crud documents. Lets take the same Parent/Child example. Create a controller by the name of Family as follows.

public function Family()
 {
  $crud = new grocery_CRUD();
  $crud->set_table('child');
  $crud->columns('ID_child','ID_Parent','Child_Name');
  $crud->set_relation('ID_Parent','Parent','Parent_Name');

  $crud->set_subject('List of Children and their Parents');

  $output = $crud->render();
  $this->_example_output($output);
 }

hurtz
  • profile picture
  • Member

Posted 18 January 2017 - 06:58 AM

sorry my mistake :(  my mind was floating when i wrote this question, i was thinking of a different scenario. hope didn't bother you much.