我正在为一个项目使用 symfony 1.4(已经开始),现在我正在更改一些东西,当我查询两个表之间的一些信息时,我得到了一个关系错误,一个已经存在,另一个是新的,应该有一个指向第一个表的外键。
我收到这样的错误消息
exception 'Doctrine_Table_Exception' with message 'Unknown relation alias ' in /var/www/testorange/symfony/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Relation/Parser.php:237
Stack trace: #0 /var/www/testorange/symfony/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Relation/Parser.php(235): Doctrine_Relation_Parser->getRelation('', false)
...
还有更多错误。
所以,我认为这是因为我的表在我在 symfony 中的定义上还没有正确的关系(它们已经在我的数据库中相关)。
我将此行添加到我的 schema.yml 然后 [更新]
OhrmTrainningSubmit:
connection: doctrine
tableName: ohrm_trainning_submit
columns:
id_trainning_submit:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
trainning:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
trainning_detail:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
answer:
type: string(250)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
state:
type: integer(1)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
user:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
OhrmUser:
local: user
foreign: emp_number
type: many
OhrmTrainning:
local: trainning
foreign: id_trainning
type: many
这是 OhrmUser 的定义
OhrmUser:
connection: doctrine
tableName: ohrm_user
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
user_role_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
emp_number:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
user_name:
type: string(40)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
user_password:
type: string(40)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
deleted:
type: integer(1)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
status:
type: integer(1)
fixed: false
unsigned: false
primary: false
default: '1'
notnull: true
autoincrement: false
date_entered:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
date_modified:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
modified_user_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
created_by:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
HsHrEmployee:
local: emp_number
foreign: emp_number
type: one
OhrmUserRole:
local: user_role_id
foreign: id
type: one
HsHrMailnotifications:
local: id
foreign: user_id
type: many
OhrmLeaveAdjustment:
local: id
foreign: created_by_id
type: many
OhrmLeaveComment:
local: id
foreign: created_by_id
type: many
OhrmLeaveEntitlement:
local: id
foreign: created_by_id
type: many
OhrmLeaveRequestComment:
local: id
foreign: created_by_id
type: many
OhrmTimesheetActionLog:
local: id
foreign: performed_by
type: many
在我要引用的表上,将引用的字段是“用户”到表“OhrmUser”到字段emp_number(我认为应该这样正确),问题是仍然是同样的错误,有人知道吗?还有什么我应该做的吗?
在我添加之后我运行这个
php symfony cc
php symfony doctrine:build-model
php symfony orangehrm:publish-assets
php symfony cc
查询
try{
$q = Doctrine_Query::create()
->select('*')
->from('OhrmTrainningSubmit TS')
->innerJoin('TS.OhrmUser U')
->addWhere("TS.trainning = $training")
->andWhere("TS.user = $employee");
$result = $q->execute();
return $result;
}catch(Exception $e){
print_r ($e->getMessage());
return null;
}
我只能访问 OhrmTrainningSubmit 的数据,但是当我尝试访问 User 的字段时,我得到了内部错误。
我收到此代码的错误
foreach ($detail as $det){
echo $det['answer']; // This is printed with no problem
//echo $det['user_name']; <-- this one comes from the table OhrmUser, I get server error with this one
}
其中 $detail 是具有查询返回值的变量。
当我做
->select('TS.*, U.*')
我得到其他错误,说
未知属性 emp_number
任何的想法?
提前致谢。