⚠ 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 n-1



macphisto
  • profile picture
  • Member

Posted 08 September 2012 - 14:48 PM

How can I set relation n-1 ???

victor
  • profile picture
  • Member

Posted 08 September 2012 - 15:16 PM

use function set_relation

macphisto
  • profile picture
  • Member

Posted 08 September 2012 - 15:34 PM

but how????? I found description only for 1-n relation

victor
  • profile picture
  • Member

Posted 08 September 2012 - 16:49 PM

what result you want to get?
why do you need this relation?

macphisto
  • profile picture
  • Member

Posted 08 September 2012 - 19:19 PM

I have invoices and these invoices have positions, and I want show invoices with positions.

victor
  • profile picture
  • Member

Posted 09 September 2012 - 07:42 AM

[indent=1]

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;
}
[/indent]

[indent=1]helped you?[/indent]
[indent=1]result:[/indent]
[indent=1][attachment=276:a_2.jpg][/indent]