У меня есть эти две модели
{
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();
Я получаю эту ошибку:
Неустранимая ошибка: Uncaught исключение 'Doctrine_Connection_Mysql_Exception 'с сообщением' SQLSTATE [42S22]: столбец не найден: 1054 Неизвестный столбец 'e.id' в 'предложении' 'в F: \ Proyectos \ Flash Moda \ code \ application \ helpers \ doctrine \ lib \ Doctrine \ Connection.php в строке 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 AS e__email_id, например..email_id IN (?))
Почему правая сторона в соединении неверна?спасибо
ОБНОВЛЕНИЕ : добавить модель группы и как я получаю $ 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));