抱歉这个非常具体的问题,我遇到过几次这个问题,而我的解决方案(不是最好的方法是重命名表格并做更多的事情),显然它不是一个真正的解决方案,这次我又遇到了同样的情况,有一张桌子我什至没有操纵,我想知道是否有人以前遇到过同样的问题。
使用 symfony 1.4 和教义,我从一个不相关的表的查询中得到这个错误
Column not found: 1054 Unknown column 'o.training_id' in 'field list'
我真的不知道出了什么问题,在我的 schema.yml 我有这样的东西
OhrmTraining:
connection: doctrine
tableName: training
columns:
id_training:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
name:
type: string(60)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
TrainingDetail:
connection: doctrine
tableName: training_detail
columns:
id_training_detail:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
training:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
OhrmTraining:
local: training
foreign: id_training
type: one
它与其他表相关 详细信息
像这样
TrainingDetail:
connection: doctrine
tableName: training_detail
columns:
id_training_deetail:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
training:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Training:
local: training
foreign: id_training
type: one
我认为这是正确的,但在我的学说/基础/BaseTraining.class 我最后有这样的东西(用于培训)
public function setUp()
{
parent::setUp();
$this->hasMany('TrainingDetail', array(
'local' => 'id', <--- this should be the id_training_detail??
'foreign' => 'training_id')); <--- this should be training?
我不知道他们为什么会这样,或者他们是否应该那样......有人可以帮我吗?
我改变了他们
public function setUp()
{
parent::setUp();
$this->hasMany('TrainingDetail', array(
'local' => 'id_training',
'foreign' => 'training'));
尽管如此,我还是得到了错误,如果我重新制作模型,一切都会消失
从数据库创建 schema.yml 文件没有简单的方法吗?
编辑:引发异常的查询是这个
$query = Doctrine_Query::create()
->from('Times a')
->where('a.employee_id = ?', $employeeId)
->orderBy('a.start_date ASC');
$results = $query->execute();
我检查了员工的基础,它与培训无关,它与培训细节有关......但不是直接与培训,我重新创建了我的模型 10 次,仍然一样