内部连接上的学说未知关系别名

发布于 2024-11-29 05:47:16 字数 4953 浏览 0 评论 0原文

这是我的数据库: 在此处输入图像描述

当我尝试使用 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('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

出了什么问题? 谢谢。

this is my database:
enter image description here

When I try with mysql this query all goes good:

SELECT *
FROM privati AS p
INNER JOIN richiestepreventivo AS r
      ON p.id = r.idPrivato
WHERE r.idImpresa = xx

But If I do:

$qr = Doctrine_Query::create()
                ->select('*')
                ->from('privati as p')
                ->innerJoin('richiestepreventivo as r ON p.id=r.idPrivato ')
                ->where('r.idImpresa=' . $idI);

But gives me this error:

Unknown relation alias 

This is my YAML file:

    ---
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

What is wrong?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蘸点软妹酱 2024-12-06 05:47:16

它应该是 ->innerJoin('p.richiestepreventivo as r ON p.id=r.idPrivato ')

更新: 尝试

$qr = Doctrine_Query::create()
            ->select('*')
            ->from('privati p')
            ->innerJoin('p.richiestepreventivo r ON p.id=r.idPrivato ')
            ->where('r.idImpresa=' . $idI);

我有一些工作代码几乎可以完成相同,并且其中没有 as 。并且,为了以防万一,请检查您生成的模型类,DQL 区分大小写。从您的 YAML 中可以清楚地看出它们应该是小写的,但也许有人重命名了它们。

It should be ->innerJoin('p.richiestepreventivo as r ON p.id=r.idPrivato ')

UPDATE: try

$qr = Doctrine_Query::create()
            ->select('*')
            ->from('privati p')
            ->innerJoin('p.richiestepreventivo r ON p.id=r.idPrivato ')
            ->where('r.idImpresa=' . $idI);

I have some working code that do almost the same and there is no as in it. And, just in case, please check your generated model classes, DQL is case-sensitive. From your YAML it is clear they should be lowercase, but maybe somebody renamed them.

墟烟 2024-12-06 05:47:16
    $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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文