Php 我能';用条令加载相关记录

Php 我能';用条令加载相关记录,php,model,doctrine,Php,Model,Doctrine,我定义了这些模型 <?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

我定义了这些模型

<?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();

}
}

是否区分大小写?请尝试
$viaje->Productor

您的Productor类似乎没有用于映射这两个类的id列。尝试添加它。但是id就是表id,不管怎样,我添加这个$this->hascollan('id','integer');在表定义和错误继续中,我将代码放在条令沙箱中并为其创建数据库,然后将一些虚拟数据放在其中。我通过Doctrine::getTable('viaje')->find(1)加载了$viaje对象;然后var_转储($viaje->Productor->toArray());并得到了预期的数据。不知道为什么你的代码不起作用,但只要我使用正确的案例,你的代码就不会有任何问题。你使用的是哪个版本的学说?你也需要改变你的方法,因为那是错误的。公共函数getProductor(){return$this->_-get('productor');}需要更改为公共函数getProductor(){return$this->_-get('productor');}@maderic_-m@Craig的答案对我来说似乎是正确的;除了“Productor”的情况外,我看不出你的代码有任何错误
$viaje->Productor
应该可以工作,一旦您将getProductor()修复为返回
$this->\u get('Productor'),它也应该可以工作
而不是
$this->\u get('productor')。既然您已经解决了案例问题,那么您会收到什么错误消息?