⚠ 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

Update on set_relation_n_n



archerwisdom
  • profile picture
  • Member

Posted 16 October 2013 - 11:27 AM

Hi,

 

I am struggling with the n-n relation tables.

 

I have 5 tables : 1 main , 1 relation table and 5 selection tables.

Listing all the tables is fine. The problem is that when I want to add or update any row using the crud EDIT button, the UPDATE works only IF I choose the table dishe.Example If I choose table dishe only, OR dishe + any( dishb or disha or dishd or dishe), then it will update the relevant tables.

 

But if I don't choose the dishe table, no update will take place.Example if I choose table disha only OR ( disha + dishb) OR (dishb only) OR (any combination of dish table except dishe), it won't update the relation table, hence no record of selection table will appear in the listing.

 

You can view the demo at 

 

http://archerwisdom.com/demo/wykcater

 

 

username : admin@admin.com

password : password

 

Click the Customer Dishes page, then try to Edit one record using combination of Set A , Set B or set C.It works ONLY IF Set E is choosen.

Note:

Set A -> table disha

Set B -> table dishb

Set C -> table dishc

Set D -> table dishd

Set D -> table dishe

 

 

 

Here is my controller code:

	public function orders()
	{
            if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
		elseif (!$this->ion_auth->is_admin()) //remove this elseif if you want to enable this for non-admins
		{
			//redirect them to the home page because they must be an administrator to view this
			return show_error('You must be an administrator to view this page.');
		}
		else
		{
		    $crud = new grocery_CRUD();
	    
		    $crud->set_table('customers');
		    $crud->set_theme('datatables');
                    $crud->set_subject('Order');

		    $crud->set_relation_n_n('disha', 'customer_dishes', 'disha', 'cust_id', 'disha_id', 'disha_name','priority');
		    $crud->set_relation_n_n('dishb', 'customer_dishes', 'dishb', 'cust_id', 'dishb_id', 'dishb_name','priority');
		    $crud->set_relation_n_n('dishc', 'customer_dishes', 'dishc', 'cust_id', 'dishc_id', 'dishc_name','priority');
                    $crud->set_relation_n_n('dishd', 'customer_dishes', 'dishd', 'cust_id', 'dishd_id', 'dishd_name','priority');
                    $crud->set_relation_n_n('dishe', 'customer_dishes', 'dishe', 'cust_id', 'dishe_id', 'dishe_name','priority');
	    
                    $crud->columns('function_address','contact_person','contact_no','function_date','dishesa','dishesb','dishesc');
                    
		    $crud->display_as('disha','Set A')
                    ->display_as('dishb','Set B')
                    ->display_as('dishc','Set C')
                    ->display_as('dishd','Set D');
                    ->display_as('dishe','Set E');
                    
                    $crud->unset_texteditor(array('function_address','function_purpose','remark'));
                    $crud->unset_columns('contact_no','function_time','function_purpose','deposit','remark');

                    $state = $crud->getState();
                    $this->load->vars( array( 'html_title' => $state." order") );
        
                    $crud->fields('function_address','contact_person','contact_no','function_date','disha','dishb','dishc','dishd');

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