учение неизвестно отношение псевдоним на внутреннее соединение - PullRequest
0 голосов
/ 11 августа 2011

это моя база данных: enter image description here

Когда я пытаюсь выполнить запрос с помощью 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

Что не так? Спасибо.

Ответы [ 2 ]

0 голосов
/ 13 августа 2011
    $qr = Doctrine_Query::create()
            ->select('r.data_invio,j.*')
            ->from('richiestepreventivo r')
            ->innerJoin('r.idPrivato j');
0 голосов
/ 11 августа 2011

Это должно быть ->innerJoin('p.richiestepreventivo as r ON p.id=r.idPrivato ')

ОБНОВЛЕНИЕ: try

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

У меня есть некоторый рабочий код, который делает почти то же самое, и нет asв этом.И, на всякий случай, проверьте ваши сгенерированные классы моделей, DQL чувствителен к регистру.Из вашего YAML ясно, что они должны быть строчными, но, возможно, кто-то их переименовал.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...