#1454: SubQuery
-------------------------+--------------------------------------------------
  Reporter:  usmanqamar  |       Owner:  romanb               
      Type:  defect      |      Status:  new                  
  Priority:  major       |   Milestone:  1.0.3                
 Component:  Record      |     Version:  1.0                  
Resolution:              |    Keywords:                       
  Has_test:  0           |    Mystatus:  Pending Core Response
 Has_patch:  0           |  
-------------------------+--------------------------------------------------
Comment (by usmanqamar):

 return $query
 ->select('s.id,s.user_id,s.heading,s.description,s.created_at,s.end_date,
 sc.consensus_rate as highest_rate')
                 ->from('Speculation s')
                 ->innerJoin('s.User u')
                 ->innerJoin('s.Category cat')
                 ->innerJoin('s.SpeculationTag st')
                 ->innerJoin('st.Tag t')
                 ->leftJoin('u.Avatar a')
                 ->leftJoin('s.SpeculationConsensus sc')
                 ->addWhere('sc.id = (SELECT MAX(sc2.id) FROM
 SpeculationConsensus sc2 WHERE sc2.speculation_id = s.id)');
 This is my query code. in last addWhere() i am using sub query. in sub-
 query the aliases assigned to sc2 is the same as it was assigned to "sc"
 one statement before in ->leftJoin('s.SpeculationConsensus sc') .. So the
 result gets wrong

 my final purpose is that when query renders its should assign new alias to
 subquery's table

 The generated query is

 SELECT DISTINCT s4.id FROM speculation s4 INNER JOIN user u2 ON s4.user_id
 = u2.id INNER JOIN category c2 ON s4.category_id = c2.id INNER JOIN
 speculation_tag s5 ON s4.id = s5.speculation_id INNER JOIN tag t2 ON
 s5.tag_id = t2.id LEFT JOIN file f2 ON u2.avatar = f2.id LEFT JOIN
 speculation_consensus s6 ON s4.id = s6.speculation_id WHERE s4.end_date >
 "2008-09-17 00:00:00" AND s6.id = (SELECT MAX(s4.id) AS s4__0 FROM
 speculation_consensus s4 WHERE s4.speculation_id = s4.id) AND s4.status IN
 (?) AND s4.deleted_at IS NULL ORDER BY s4.end_date ASC LIMIT 2 - (0 )


 here you can see the aliases

 waiting for ur reply

-- 
Ticket URL: <http://trac.doctrine-project.org/ticket/1454#comment:3>
Doctrine <http://www.phpdoctrine.org>
PHP Doctrine Object Relational Mapper
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"doctrine-svn" group.
 To post to this group, send email to [email protected]
 To unsubscribe from this group, send email to [EMAIL PROTECTED]
 For more options, visit this group at 
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---

Reply via email to