⚠ 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 assign only unassigned items ?



Christophe Conduché
  • profile picture
  • Member

Posted 15 April 2013 - 13:34 PM

I have 2 tables :

 

Table 1 : pilot

pilot_id

pilot_name

 

Table 2 : glider

glider_id

glider_name

pilot_id

 

how to set up a 1:n relation in order that I can affect gliders to pilots, and only gliders not yet assigned to a pilot (pilot_id null in glider) and when I unassign a glider from a pilot the pilot_id in glider comes to null again ?

 


Christophe Conduché
  • profile picture
  • Member

Posted 15 April 2013 - 14:47 PM

I think I have found a solution, with a link to create a glider on the edit form of table1, and reversing the n:1 on the pilot (table1) to a 1:n on the glider.

$crud->set_relation('user_id','users','username',array('status' => 'active'),'priority ASC');

 

and on the table1, i will display the list of the gliders by adapting this code :

 

function list_invoices()
{
  $crud = new grocery_CRUD();
  $crud->set_table('invoices');
  $crud->set_subject('invoices');
// add a new column "positions"
  $crud->columns('invoices_id','company_name','positions');
  $crud->callback_column('positions', array($this, 'positions'));
  $output = $crud->render();

  $this->load->view('header',$output);
}
function positions($value, $row)
{
    $html = '<ul>';
    $positions = $this->db->get_where('positions',array('invoices_id'=>$row->invoices_id))->result_array();
    if($positions)
    {
       foreach ($positions as $items)
      {
       $html.='<li>'.$items['title'].'</li>';
      }
    }
    $html.='</ul>';
    return $html;
}
 

 

but I have still a problem on the add/edit of pilots. How to display the gliders of the pilot ?