⚠ 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

'set_relation' 1 to n drop down not functioning



aleifuu
  • profile picture
  • Member

Posted 20 December 2017 - 04:57 AM

Ok. So I won't post a question unless search to forums/googling don't help I just start learning CI and just learned GroceryCRUD - a great product btw ! -, to help me with all redundant creating form just to insert/view/delete. perfect solution to my case Now, I have a dead simple problem but for the life of me I just couldn't figure out why or how to debug yet.

 

I just need to 'set_relation' between 2 tables so that the related_field will just show dropdown and I can proceed normally Here are those 2 table structures:

Warehouse_Items 
- ID [primary] 
- Nama 
Warehouse_Records 
- ID [primary] 
- Tanggal 
- Barang ( I need to link this field 'Barang' to 'Nama' in table Warehouse_Items ) 

this is the line to do that 

$crud->set_relation('Barang', 'Warehouse_Items', 'Nama'); 

but, dropdown doesn't come out when add/edit

 

Maybe someone could share a thought ?


Amit Shah
  • profile picture
  • Member

Posted 20 December 2017 - 08:53 AM

share the method code - so one can look at as why things are not working. As such, it works in seamlessly for others and so it should for you too. 


aleifuu
  • profile picture
  • Member

Posted 21 December 2017 - 03:20 AM

public function warehouse_records()
        {
                try{
                $crud = new grocery_CRUD();
                $crud->set_theme('datatables');
                $crud->set_table('warehouse_records');
                $crud->columns('ID','Tanggal','Barang','Keterangan','Bal','Kg');

                // change some field type
                $crud->field_type('Barang','string');
                //$crud->field_type('Keterangan','string');
                $crud->field_type('Keterangan','dropdown', array('1' => 'option_1', '2' => 'option_2','3' => 'option_3' , '4' => 'option_4'));

                //$crud->display_as('Barang','Nama Barang');

                // relation to warehouse_products
                //$crud->set_relation('Barang','warehouse_items','ID');
                $crud->set_relation('Barang','warehouse_items','Nama');

                // some callback()
                $crud->callback_column('Barang',array($this,'_column_bonus_right_align'));

                // Output time
                $output = $crud->render();
                $output->title = "Warehouse Items Form";
                $output->meta_keywords = "Something and SEO";
                $this->_example_output($output);

                }catch(Exception $e){
                        show_error($e->getMessage().' --- '.$e->getTraceAsString());
                }
        }

here we go


Amit Shah
  • profile picture
  • Member

Posted 21 December 2017 - 05:39 AM

Well - here we go - look @the issue you created ...

public function warehouse_records()
        {
                try{
                $crud = new grocery_CRUD();
                $crud->set_theme('datatables');
                $crud->set_table('warehouse_records');
                $crud->columns('ID','Tanggal','Barang','Keterangan','Bal','Kg');

                // change some field type
                $crud->field_type('Barang','string');
                //$crud->field_type('Keterangan','string');
                $crud->field_type('Keterangan','dropdown', array('1' => 'option_1', '2' => 'option_2','3' => 'option_3' , '4' => 'option_4'));

                //$crud->display_as('Barang','Nama Barang');

                // relation to warehouse_products
                //$crud->set_relation('Barang','warehouse_items','ID');
                $crud->set_relation('Barang','warehouse_items','Nama');

                // some callback()
                $crud->callback_column('Barang',array($this,'_column_bonus_right_align'));

                // Output time
                $output = $crud->render();
                $output->title = "Warehouse Items Form";
                $output->meta_keywords = "Something and SEO";
                $this->_example_output($output);

                }catch(Exception $e){
                        show_error($e->getMessage().' --- '.$e->getTraceAsString());
                }
        }

You are setting the relation - fine with it.. but then you are also setting a type to the same... that might be overriding the GC's natural feature to treat the field for relation and rather set it as a simple string / textbox. GC won't automatically remove the field type that is being set against the relation you are setting. It takes that field type while it gets rendered. Hence you are not able to see the relation dropdown.


aleifuu
  • profile picture
  • Member

Posted 21 December 2017 - 11:19 AM

Yupe Amit Shah, that's the one  :)

 

Many thanks for clearing up my writer/coder's block ! Now I can resume building more things on top of it

 

Cheers