我有这两种型号的
{
class Email extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('email');
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('nombre', 'string', 40, array(
'type' => 'string',
'length' => 40,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('email', 'string', 90, array(
'type' => 'string',
'length' => 90,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('estado', 'integer', 1, array(
'type' => 'integer',
'length' => 1,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'default' => '1',
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('borrado', 'integer', 1, array(
'type' => 'integer',
'length' => 1,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('created_at', 'timestamp', null, array(
'type' => 'timestamp',
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('updated_at', 'timestamp', null, array(
'type' => 'timestamp',
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
}
public function setUp()
{
parent::setUp();
$this->hasMany('Grupo as Grupos', array(
'refClass' => 'EmailGrupo',
'local' => 'email_id',
'foreign' => 'grupo_id'));
$this->hasMany('Envio as Envios', array(
'local' => 'email_id',
'foreign' => 'envio_id',
'refClass' => 'EnvioEmail'));
}
//setters
public function setId($id) { $this->_set('id', $id); }
public function setNombre($nombre) { $this->_set('nombre', $nombre); }
public function setEmail($email) { $this->_set('email', $email); }
public function setEstado($estado) { $this->_set('estado', $estado); }
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 getEmail() { return $this->_get('email'); }
public function getEstado() { return $this->_get('estado'); }
public function getBorrado() { return $this->_get('borrado'); }
public function getGrupos() { return $this->_get('Grupos'); }
public function getEnvios() { return $this->_get('Envios'); }
public function delete(){
$this->setBorrado(1);
$this->save();
}
}
}
{
class EmailGrupo extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('email_grupo');
$this->hasColumn('email_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => false,
));
$this->hasColumn('grupo_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => false,
));
}
public function setUp()
{
parent::setUp();
$this->hasOne('Email', array(
'local' => 'email_id',
'foreign' => 'id'));
$this->hasOne('Grupo', array(
'local' => 'grupo_id',
'foreign' => 'id'));
}
// setters
public function setEmailId($email_id) { $this->_set('email_id', $email_id); }
public function setGrupoId($grupo_id) { $this->_set('grupo_id', $grupo_id); }
// getters
public function getEmailId() { return $this->_get('email_id'); }
public function getGrupoId() { return $this->_get('grupo_id'); }
}
}
当我试图让"Grupos"执行$email->getGrupos();
时,我得到了这个错误:
致命错误:未捕获异常"Doctrine_Connection_Mysql_exception"带有消息"SQLSTATE[42S22]:未找到列:1054未知F:''Proyectos''Flash中子句"的"中的列"e.id"Moda''code''application''helpers''doctrine''lib''doctrine''Connection.php on第1083行。
我记录查询,我得到:
选择g.id AS g_id,g.nombre AS g_nombre,g.borrado AS g_borrado,g.created_at AS g_created_at、g.updated_at AS g_updated_at,e.email_id作为e_email_id,e.grupo_id作为e_grupo_id从grupo g向左加入email_grupo e ON g.id=e.id WHERE(e.email_id IN(?))
为什么连接中的右侧是错误的?感谢
更新:添加grupo模型以及我如何获得$email
class Grupo extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('grupo');
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('nombre', 'string', 40, array(
'type' => 'string',
'length' => 40,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('borrado', 'integer', 1, array(
'type' => 'integer',
'length' => 1,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('created_at', 'timestamp', null, array(
'type' => 'timestamp',
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('updated_at', 'timestamp', null, array(
'type' => 'timestamp',
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
}
public function setUp()
{
parent::setUp();
$this->actAs('Timestampable');
$this->hasMany('Email as Emails', array(
'local' => 'id',
'foreign' => 'grupo_id',
'refClass' => 'EmailGrupo'
)
);
$this->hasMany('Envio as Envios', array(
'local' => 'id',
'foreign' => 'grupo_id',
'refClass' => 'EnvioGrupo'
)
);
}
//setters
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'); }
public function delete(){
$this->setBorrado(1);
$this->save();
}
}
$email = Doctrine::getTable('Email')->find($this->uri->segment(4,0));
错误在grupo模型中,这是正确的模型:
class Grupo extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('grupo');
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('nombre', 'string', 40, array(
'type' => 'string',
'length' => 40,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('borrado', 'integer', 1, array(
'type' => 'integer',
'length' => 1,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('created_at', 'timestamp', null, array(
'type' => 'timestamp',
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('updated_at', 'timestamp', null, array(
'type' => 'timestamp',
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
}
public function setUp()
{
parent::setUp();
$this->actAs('Timestampable');
$this->hasMany('Email as Emails', array(
'local' => 'grupo_id',
'foreign' => 'email_id',
'refClass' => 'EmailGrupo'
)
);
$this->hasMany('Envio as Envios', array(
'local' => 'grupo_id',
'foreign' => 'envio_id',
'refClass' => 'EnvioGrupo'
)
);
}
//setters
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'); }
}
我用电子邮件更改定义relaicon的行。