开发者

I can't load related records with Doctrine

开发者 https://www.devze.com 2023-02-16 23:45 出处:网络
I define these models <?php class Viaje extends Doctrine_Record { public function setTableDefinition() {

I define these models

<?php
class Viaje extends Doctrine_Record {

public function setTableDefinition() {
$this->hasColumn('fecha', 'date');
$this->hasColumn('productor_id', 'integer');
$this->hasColumn('transporte_id', 'integer');
$this->hasColumn('chofer_id', 'integer');
$this->hasColumn('desde', 'string');
$this->hasColumn('hasta', 'string');
$this->hasColumn('kilometros', 'decimal');
$this->hasColumn('comision', 'decimal');
$this->hasColumn('tarifa_transportadora', 'decimal');
$this->hasColumn('tarifa_transporte', 'decimal');
$this->hasColumn('cargos_extras', 'decimal');
$this->hasColumn('imputado', 'integer', 1, array('default' =>0));
$this->hasColumn('borrado', 'integer', 1, array('default' =>0));

}

public function setUp() {
$this->setTableName('viaje');
$this->actAs('Timestampable');

$this->hasOne('Productor', array(
                'local' => 'productor_id',
                'foreign' => 'id')
        );

        $this->hasOne('Transporte', array(
                'local' => 'transporte_id',
                'foreign' => 'id')
        );

        $this->hasOne('Chofer', array(
                'local' => 'chofer_id',
                'foreign' => 'id')
        );

        $this->hasMany('Chofer as Choferes', array(
            'local' => 'id',
            'foreign' => 'transporte_id')
     );

}

// setters
public function setID($id) { $this->_set('id', $id); }
public function setFecha($fecha) { $this->_set('fecha', $fecha); }
public function setProductorID($productorID) { $this->_set('productor_id',
$productorID); }
public function setProductor($productor) { $this->_set('productor',
$productor); }
public function setTransporteID($transporteID) {
$this->_set('transporte_id', $transporteID); }
public function setTransporte($transporte) { $this->_set('transporte',
$transporte); }
public function setChoferID($choferID) { $this->_set('chofer_id',
$choferID); }
public function setChofer($chofer) { $this->_set('chofer', $chofer); }
public function setDesde($desde) { $this->_set('desde', $desde); }
public function setHasta($hasta) { $this->_set('hasta', $hasta); }
public function setKilometros($kilometros) { $this->_set('kilometros',
$kilometros); }
public function setComision($comision) { $this->_set('comision', $comision);
}

public function setTarifaTransportadora($tarifaTransportadora) {
$this->_set('tarifa_transportadora', $tarifaTransportadora); }
public function setTarifaTransporte($tarifaTransporte) {
$this->_set('tarifa_transporte', $tarifaTransporte); }
public function setCargosExtras($cargosExtras) {
$this->_set('cargos_extras', $cargosExtras); }
public function setImputado($imputado) { $this->_set('imputado', $imputado);
}

public function setBorrado($borrado) { $this->_set('borrado', $borrado); }

// getters
public function getID() { return $this->_get('id'); }
public function getFecha() { return $this->_get('fecha'); }
//public function getProductorID() { return $this->_get('productor_id'); }
/*
 * @return Productor
 */
public function getProductor() { return $this->_get('productor'); }
//public function getTransporteID() { return $this->_get('transporte_id'); }
/*
 * @return Transporte
 */
public function getTransporte() { return $this->_get('transporte'); }
//public function getChoferID() { return $this->_get('chofer_id'); }
/*
 * @return Chofer
 */
public function getChofer() { return $this->_get('chofer'); }
public function getDesde() { return $this->_get('desde'); }
public function getHasta() { return $this->_get('hasta'); }
public function getKilometros() { return $this->_get('kilometros'); }
public function getComision() { return $this->_get('comision'); }
public function getTarifaTransportadora() { return
$this->_get('tarifa_transportadora'); }
public function getTarifaTransporte() { return
$this->_get('tarifa_transporte'); }
public function getCargosExtras() { return $this->_get('cargos_extras'); }
public function getImputado() { return $this->_get('imputado'); }
public function getBorrado() { return $this->_get('borrado'); }

/**
 * Marca como borrado un transporte
 */
public function delete(){
$this->setBorrado(1);
$this->save();
}
}

<?php
class Productor extends Doctrine_Record {

public function setTableDefinition() {
$this->hasColumn('nombre', 'string', 60);
$this->hasColumn('borrado', 'integer', 1, array('default' =>0));

}

public function setUp() {
 $this->setTableName('productor');
$this->actAs('Timestampable');

}

public function setID($id) { $this->_set('id', $id); }
public function setNombre($nombre) { $this->_set('nombre', $nombre); }
public function setBorrado($borrado) { $this->_set('开发者_如何转开发borrado', $borrado); }

// getters
public function getID() { return $this->_get('id'); }
public function getNombre() { return $this->_get('nombre'); }
public function getBorrado() { return $this->_get('borrado'); }

/**
 * Marca como borrado un transporte
 */
public function delete(){
$this->setBorrado(1);
$this->save();
}
}

<?php
class Transporte extends Doctrine_Record {

public function setTableDefinition() {
$this->hasColumn('nombre', 'string', 60);
$this->hasColumn('cuit', 'integer', 11);
$this->hasColumn('borrado', 'integer', 1, array('default' =>0));

}

public function setUp() {
 $this->setTableName('transporte');
$this->actAs('Timestampable');
 $this->hasMany('Chofer as Choferes', array(
            'local' => 'id',
            'foreign' => 'transporte_id'
        ));
}

 // setters
public function setNombre($nombre) { $this->nombre = $nombre; }
public function setCUIT($cuit) { $this->cuit = $cuit; }
public function setBorrado($borrado) { $this->borrado = $borrado; }
 // getters
public function getNombre() { return $this->nombre; }
public function getCUIT() { return $this->cuit; }
public function getBorrado() { return $this->borrado; }

/**
 * Marca como borrado un transporte
 */
public function delete(){
$this->setBorrado(1);
$this->save();

}
}

<?php
class Chofer extends Doctrine_Record {

public function setTableDefinition() {
$this->hasColumn('transporte_id', 'integer', 10);
$this->hasColumn('nombre', 'string', 60);
$this->hasColumn('cuil', 'integer', 11);
$this->hasColumn('dominio', 'string', 6);
$this->hasColumn('borrado', 'integer', 1, array('default' =>0));

}

public function setUp() {
parent::setUp();
 $this->setTableName('chofer');
$this->actAs('Timestampable');
}

 // setters
public function setTransporteId($transporte_id) { $this->transporte_id =
$transporte_id; }
public function setNombre($nombre) { $this->nombre = $nombre; }
public function setCUIL($cuil) { $this->cuil = $cuil; }
public function setDominio($dominio) { $this->dominio = $dominio; }
public function setBorrado($borrado) { $this->borrado = $borrado; }
 // getters
public function getTransporteId() { return $this->transporte_id; }
public function getNombre() { return $this->nombre; }
public function getCUIT() { return $this->cuit; }
public function getDominio() { return $this->dominio; }
public function getBorrado() { return $this->borrado; }

/**
 * Marca como borrado un transporte
 */
public function delete(){
$this->setBorrado(1);
$this->save();

}
}

But when I do $viaje = Doctrine::getTable('Viaje')->find(1); and try to access $viaje->productor or $viaje->getProductor(), I get this exception:

Fatal error: Uncaught exception 'Doctrine_Record_UnknownPropertyException' with message 'Unknown record property / related component "productor" on "Viaje"' in F:\Proyectos\TDT Apps\code\application\helpers\doctrine\lib\Doctrine\Record\Filter\Standard.php:55

Stack trace:

#0 F:\Proyectos\TDT Apps\code\application\helpers\doctrine\lib\Doctrine\Record.php(1395): Doctrine_Record_Filter_Standard->filterGet(Object(Viaje), 'productor')

#1 F:\Proyectos\TDT Apps\code\application\models\viaje.php(71): Doctrine_Record->_get('productor')

#2 F:\Proyectos\TDT Apps\code\application\controllers\dashboard.php(20): Viaje->getProductor()

#3 [internal function]: Dashboard->index()

#4 F:\Proyectos\TDT Apps\code\system\core\CodeIgniter.php(297): call_user_func_array(Array, Array)

#5 F:\Proyectos\TDT Apps\code\index.php(163): require_once('F:\Proyectos\TD...')

#6 {main} thrown in F:\Proyectos\TDT Apps\code\application\helpers\doctrine\lib\Doctrine\Record\Filter\Standard.php on line 55

Why can't I load the related records?


Is it case sensitive? Try $viaje->Productor instead?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号