Well, I have 3 tables: sorty with fields id, name, fStart, fEnd bol with fields id, fol, and bol_sorty with id, bol_id, sorty_id
When I add a new register to sorty, it must add to bol the number of items from fstart to fEnd. I know how to create a new object and insert it to the table but I can't undesteand anything about relations [I'm trying], Already read the code igniter and datamapper guide, I'm new on this.
something like this: MODEL:
public function agregar() {
$nombre=$this -> input -> post('nombre');
$folio_inicial=$this -> input -> post('folioInicial');
$folio_final= $this -> input -> post('folioFinal');
$u = new Sorteo();
$u -> nombre = $nombre;
$u -> folio_inicial = $folio_inicial;
$u -> folio_final = $folio_final;
$u -> costo = $this -> input -> post('costo');
$u -> save();
/*for( $i=$folio_inicial; $i<=$folio_final; $i++ ){
$b=new Boleto();
$b->folio=$i;
$b->estado=2;
$b->condicion=2;
$b->campus=4;
$b->save();
//$u->save($b);
}
/* $this->load->model('sorteos/model_boleto');
$this->model_boleto->agregar($nombre, $folio_final,$folio_inicial);
/*if ($u -> save())
return true;
else
return false;*/
}
AND CONTROLLER
public function procesar_sorteo_nuevo() {
$this -> form_validation -> set_rules('nombre', 'Nombre', 'trim|required|is_unique[sorteos.nombre]');
$this -> form_validation -> set_rules('folioInicial', 'Folio Inicial', 'trim|required|callback_chequear');
$this -> form_validation -> set_rules('folioFinal', 'Folio Final', 'trim|required');
$this -> form_validation -> set_rules('costo', 'Costo', 'trim|required');
if ($this -> form_validation -> run()) {
if ($this -> model_sorteo -> agregar()) {
echo "Sorteo Creado";
} else {
echo "ERROR FATAL";
}
//redirect('/sorteos/sorteos/');
}
}