Witam jak zrobić takie coś?
Poniżej przedstawiam zapytanie:

Kod w php:
  1. $recordsObjs = Doctrine_Query::create()
  2. ->select('c.id as clientid, e.id as eventid')
  3. ->addSelect('(select name_surname from client_contact where client = c.id limit 1) as name_surname')
  4. [b]->addSelect('(select count(*) from reservation where event = e.id and client = c.id and dict_reservation_status = 2) as unconfirmed_count')[/b]
  5. ->from('Reservation r')
  6. ->innerJoin('r.Client c')
  7. ->innerJoin('r.Event e')
  8. ->groupBy('c.id, e.id');



  1.  
  2. SELECT c.id AS c__0, e.id AS e__1,
  3. (SELECT r.name_surname FROM client_contact WHERE r.client = c.id LIMIT 1) AS r__8,
  4. [b](SELECT COUNT(*) FROM reservation WHERE r.event = e.id AND r.client = c.id AND r.dict_reservation_status = 2) AS r__11 FROM reservation r [/b]
  5. INNER JOIN client c ON r.client = c.id
  6. INNER JOIN event e ON r.event = e.id
  7. GROUP BY c.id, e.id
  8. ORDER BY c__2 ASC
  9.  


Chodzi o wyróżnione linijki nie chcę aby Doctrine traktował tego
  1. event = e.id and client = c.id

tak
  1. r.event = e.id AND r.client = c.id


tylko jako oddzielny model. Próbowałem już tak:
  1. ->addSelect('(select count(*) from reservation r2 where r2.event = e.id and r2.client = c.id and r2.dict_reservation_status = 2) as unconfirmed_count')


ale wyrzuca błąd:
Couldn't find class r2

czyli tak się nie da....Chodzi o to żeby zastosować tak jakby zewnętrzne zapytanie (r2) stosując łączenie z istniejącym modelem (r2.event(wyniki z zewntątrz) = e.id(zadeklarowane modele) and r2.client(wyniki z zewnątrz) = c.id(zadeklarowane modele).

Problem jest w tym, że doctrine traktuje de facto drugą tabelę reservation jako jedną i tą samą reservation, a powinien traktować jako coś zupełnie nowego.

Gdyby ktoś chciał mi pomóc to proszę o odpowiedź.


Rozwiązałem problem....


Zamieniłem na takie coś....po prostu dodałem alias:
  1.  
  2. ->addSelect('(select count(*) from reservation r where r.event = e.id and r.client = c.id and r.dict_reservation_status = 2) as confirmed_count')
  3.