Mysql innerjoin上未知的关系别名
这是我的数据库: 当我尝试使用mysql时,这个查询一切正常:Mysql innerjoin上未知的关系别名,mysql,join,doctrine,Mysql,Join,Doctrine,这是我的数据库: 当我尝试使用mysql时,这个查询一切正常: SELECT * FROM privati AS p INNER JOIN richiestepreventivo AS r ON p.id = r.idPrivato WHERE r.idImpresa = xx 但如果我这样做: $qr = Doctrine_Query::create() ->select('*') ->from('pr
SELECT *
FROM privati AS p
INNER JOIN richiestepreventivo AS r
ON p.id = r.idPrivato
WHERE r.idImpresa = xx
但如果我这样做:
$qr = Doctrine_Query::create()
->select('*')
->from('privati as p')
->innerJoin('richiestepreventivo as r ON p.id=r.idPrivato ')
->where('r.idImpresa=' . $idI);
但给了我一个错误:
Unknown relation alias
这是我的YAML文件:
---
detect_relations: true
options:
collate: latin1_swedish_ci
charset: latin1
type: InnoDB
exclienti:
columns:
id:
type: integer(4)
primary: true
notnull: true
regione:
type: string(25)
notnull: true
data_reg:
type: date
notnull: true
default: '0000-00-00'
provincia:
type: string(2)
notnull: true
azienda:
type: string(25)
notnull: true
telefono:
type: string(25)
notnull: true
email:
type: string(25)
notnull: true
RM:
type: integer(4)
notnull: true
p1:
type: string(2)
notnull: true
p2:
type: string(2)
notnull: true
p3:
type: string(2)
notnull: true
p4:
type: string(2)
notnull: true
p5:
type: string(2)
notnull: true
p6:
type: string(2)
notnull: true
p7:
type: string(2)
notnull: true
p8:
type: string(2)
notnull: true
note:
type: string(255)
notnull: true
prevInviati:
type: integer(4)
notnull: true
default: '0'
nIscrizioni:
type: integer(4)
notnull: true
default: '0'
idImpresa:
type: integer(4)
notnull: true
data_form:
type: date
notnull: true
default: '0000-00-00'
options:
charset: latin1
imprese:
columns:
id:
type: integer(4)
primary: true
notnull: true
autoincrement: true
regione:
type: string(25)
notnull: true
data_form:
type: date
notnull: true
data_reg:
type: date
default: '0000-00-00'
provincia:
type: string(2)
notnull: true
azienda:
type: string(25)
notnull: true
telefono:
type: string(25)
notnull: true
email:
type: string(25)
notnull: true
RM:
type: integer(4)
default: '0'
p1:
type: string(2)
notnull: true
default: ''
p2:
type: string(2)
notnull: true
default: ''
p3:
type: string(2)
notnull: true
default: ''
p4:
type: string(2)
notnull: true
default: ''
p5:
type: string(2)
notnull: true
default: ''
p6:
type: string(2)
notnull: true
default: ''
p7:
type: string(2)
notnull: true
default: ''
p8:
type: string(2)
notnull: true
default: ''
note:
type: string(255)
default: ''
prevInviati:
type: integer(4)
notnull: true
default: '0'
nIscrizioni:
type: integer(4)
default: '0'
options:
charset: latin1
privati:
columns:
id:
type: integer(4)
primary: true
notnull: true
autoincrement: true
data:
type: date
default: null
regione:
type: string(20)
default: null
provincia:
type: string(20)
default: null
nome:
type: string(25)
default: null
telefono:
type: string(25)
notnull: true
email:
type: string(30)
default: null
richiesta:
type: string(255)
default: null
cod1:
type: integer(4)
default: '0'
cod2:
type: integer(4)
default: '0'
cod3:
type: integer(4)
default: '0'
cod4:
type: integer(4)
default: '0'
cod5:
type: integer(4)
default: '0'
note:
type: string(255)
default: null
options:
charset: latin1
richiestepreventivo:
columns:
id:
type: integer(4)
primary: true
notnull: true
autoincrement: true
idPrivato:
type: integer(4)
notnull: true
idImpresa:
type: integer(4)
notnull: true
data_invio:
type: date
notnull: true
relations:
idImpresa:
class: imprese
local: idImpresa
foreign: id
foreignAlias: richiestepreventivoes
onDelete: cascade
idPrivato:
class: privati
local: idPrivato
foreign: id
foreignAlias: richiestepreventivoes
indexes:
1 impresa piu richieste preventivo:
fields: [idImpresa]
FKRichiesteP160761:
fields: [idPrivato]
options:
charset: latin1
怎么了?
谢谢。应该是->内部加入'p.id=r.idPrivato'p.richestepreventivo as r ON p.id=r.idPrivato'
更新:尝试
我有一些工作代码,做几乎相同的,没有作为在它。为了以防万一,请检查生成的模型类,DQL区分大小写。从您的YAML中可以清楚地看出,它们应该是小写的,但可能有人重命名了它们。可能重复no,您发布的内容是关于加入mysql而不带条令。对于您的更新查询,我返回了:未知关系别名richiestepreventivo…..richiestepreventivo是一个表,而不是一个私有字段如果您很好奇为什么这些查询在应该有的时候不起作用,在这两段代码中,您的reliation别名的名称末尾都有一个拼写错误,即缺少“es”。我想你在寻找:'>innerJoin'p.RichiestepPreventivoes r'这应该是可以接受的答案。最好在不指定连接条件的情况下引用别名,除非执行多个条件,并让条令在幕后处理它。
$qr = Doctrine_Query::create()
->select('r.data_invio,j.*')
->from('richiestepreventivo r')
->innerJoin('r.idPrivato j');
$qr = Doctrine_Query::create()
->select('r.data_invio,j.*')
->from('richiestepreventivo r')
->innerJoin('r.idPrivato j');