[eluser]Asinox[/eluser]
Hi guys, im new with Datamapper and ORM in this way.. just i know about the Django Magic..so im tying to save data with relationship, but the data is saving just in one table and dont save the relation in the relationship table...sorry with my english.
some help please?
MODELS
Sala Model
Code:
//sala model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sala extends DataMapper{
var $has_many = array('horario');
var $has_one = array("cine");
var $table = 'salas';
function Sala(){
parent::DataMapper();
}
}
Cine Model
Code:
// Cine model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cine extends DataMapper{
public $has_many = array('sala');
var $table = 'cines';
function Cine(){
parent::DataMapper();
}
}
CONTROLLERS
Code:
//Salas Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Salas extends Controller{
function Salas(){
parent::Controller();
error_reporting(E_ALL);
}
// listamos salas
function index(){
$data['titulo'] = 'Listando salas';
$salas = new Sala();
$data['query'] = $salas->get()->all;
$this->load->vars($data);
$this->load->view('admin_sala_index');
}
//agregamos sala
function addSala(){
$data['titulo'] = 'Agregar sala';
$cines = new Cine();
$data['query']= $cines->get()->all;
$this->load->vars($data);
$this->load->view('admin_sala_add');
}
//HERE IS IM SAVING "sala and cine relation..but is not working.."
function doAdd(){
if($this->form_validation->run('add_sala')==FALSE){
$this->addSala();
}else{
$sala = new Sala();
$sala->sala = $this->input->post('nombre');
$cine = new Cine();
$cine->id = $this->input->post('cine');
$cine->where('id',$id)->get();
$sala->save($cine);
redirect('admin/salas/');
}
}