2012-02-06 152 views
0

我有这两个型号错误 - >列未找到:1054未知列在“e.id“的条款”

{ 
    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();我得到这个错误:

Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.id' in 'on clause'' in F:\Proyectos\Flash Moda\code\application\helpers\doctrine\lib\Doctrine\Connection.php on line 1083.

我日志查询和获取:

SELECT 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 AS e__email_id, e.grupo_id AS e__grupo_id FROM grupo g LEFT JOIN email_grupo e ON g.id = e.id WHERE (e.email_id IN (?))

为什么右侧上加入重新错了吗?感谢

UPDATE:添加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' => '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)); 
+0

你可以发布你获得'$ email' var的方式,还有一个模型 - 'Grupo',看起来像在那个模型中有错误。 – devdRew 2012-02-06 15:29:49

+0

我更新了Grupo的定义以及我如何获得$ meail的问题 – 2012-02-06 16:09:13

回答

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'); } 


} 

我焊割线用Email定义relaicon。

相关问题