⚠ 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

How to add new seletion field (with relation 1-n)



Hồ Thế Vũ
  • profile picture
  • Member

Posted 02 November 2016 - 13:05 PM

Hi all,

I have 2 tables: category and product as below:

Category: id, name
Product: id, category_id, name (category_id is the foreign key to category table)
When I added a new record at product page, my expected: category_id field is a selection box (refer to category table)
Anyone can help me this issue?
Thank you so much! ( sorry for my poor English)

My code as below:

public function category(){
$crud = new grocery_CRUD();


$crud->set_theme('datatables');
$crud->set_table('category');
$crud->columns('name');
$crud->fields('name', 'has_parent');


$crud->unset_print();
$crud->unset_export();


$crud->required_fields('name');
$crud->set_relation('id', 'product','category_id');


$output = $crud->render();


$this->_example_output($output);
}


public function product(){
$crud = new grocery_CRUD();


$crud->set_theme('datatables');
$crud->set_table('product');
$crud->columns('name', 'code', 'price', 'category_id', 'description');


$crud->unset_print();
$crud->unset_export();


$crud->required_fields('name', 'code', 'price', 'category_id');


$output = $crud->render();


$this->_example_output($output);
}

Hồ Thế Vũ
  • profile picture
  • Member

Posted 03 November 2016 - 08:19 AM

Thank all, the problem has solved :)