⚠ 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

I have question about set relation 1_n for more that 2 tables



vladbutterfly

vladbutterfly
  • profile picture
  • Member

Posted 26 April 2013 - 11:43 AM


I have this relations in my database for 3 tables
 project-->customer-->customer_group
  project(customer_id)-->custmer(cutomer_group_id)-->cutomer_group(id)
I need to display in my crud datable all infomation about the project and also the name of the custmer group which is the third table
and I couldnt really find a solution for that
please help me
thanks


jjwdesign

jjwdesign
  • profile picture
  • Member

Posted 27 April 2013 - 02:29 AM

Use the $crud->callback_column method to populate any custom data for your datatable. You may require multiple method calls to your models. It might not be efficient, but you should be able to get the proper data. You will not be able to edit it using the add/edit crud, but it should be able to be placed in your listing view (datatable).

 

http://www.grocerycrud.com/examples/callback_column_example


vladbutterfly

vladbutterfly
  • profile picture
  • Member

Posted 27 April 2013 - 13:16 PM

hi jjwdesign

Thank you for your response But actually im a very beginner in CodeIgniter and GCrud and I didint really understand you explanation

sorry but could you please make it more clear for me

 

 

jjwdesign

jjwdesign
  • profile picture
  • Member

Posted 27 April 2013 - 16:38 PM

Grocery CRUD only has the two relationship methods that I know of.

 

http://www.grocerycrud.com/documentation/options_functions/set_relation

and

http://www.grocerycrud.com/examples/set_a_relation_n_n

 

But, you can create your own methods for the data you need. You need to develop your own model methods to get the data needed to fill your table columns.

 

http://www.grocerycrud.com/documentation/options_functions/callback_column

 

==========

 

For example, your customer group column.

 

$crud->callback_column('cutomer_group_name', array($this, '_cutomer_group_name_callback'));

 

 

Then in your controller, create method for the callback function.

 

function _cutomer_group_name_callback($value, $row) {

    ...write your custom SQL code here... (your custom model method)

}

 


vladbutterfly

vladbutterfly
  • profile picture
  • Member

Posted 28 April 2013 - 09:10 AM

hi JJwebdesign

Thank you for helping me

is that what you want me to do??

   public function project_management()
    {
        
    $crud = new grocery_CRUD();
    //$crud->set_theme('datatables');
    $crud->set_relation('project_status_id','project_status','id');
    $crud->display_as('project_status_id','Project Identifier');
    $crud->set_relation('customer_id','customer','name');
    $crud->display_as('customer_id','Customer Identifier');
    $crud->set_relation('manager_id','resource','first_name');
    $crud->display_as('manager_id','Manager Name');
    $crud->set_table('project');
    $crud->columns('project_status_id','description','redmine_id','change_date');
    $crud->callback_column('id',array($this,'_callback_customer_group'));
     $crud->set_subject('Project');
   
 
    $output = $crud->render();
 
    $this->_example_output($output);
    }
    
    public function _callback_customer_group()
{
     $crud->set_table('customer');
     $crud->set_subject('Customer');
     $crud->set_relation('customer_group_id','cutomer_group','id');
    $crud->display_as('customer_group_id','Customer group Identifier');
}