2013-11-21 3 views
0

나는CreateQuery 교리 심포니 2 StateFieldPathExpression

다음
public function getFoo($profilo_id){ 
    $em = $this->getEntityManager(); 
    $query = $em->createQuery(' 
    SELECT l.id as like_id, l.spotted_id as spotted_id,count(l.spotted_id) as numero_likes 
    FROM SNLikeBundle:LikeSpotted l 
    LEFT JOIN SNFotoBundle:Foto f 
    WITH f.id = l.spotted_id 
    LEFT JOIN SNProfiloBundle:Profilo p 
    WITH f.profilo_id = p.id 
    WHERE p.id = :profilo_id 
    GROUP BY l.spotted_id 
    ORDER BY numero_likes DESC 
    ')->setFirstResults(0) 
    ->setMaxResults(10) 
    ->setParameter('profilo_id', $profilo_id); 

    $results = $query->getResult(); 
    return $results; 


} 

내가 가진이 오류

[Semantical Error] line 0, col 36 near 'spotted_id as': Error: Class SN\LikeBundle\Entity\LikeSpotted has no field or association named spotted_id 

내가 변경을 선택 교리에서이 작업을 수행하려고 MySQL의

SELECT l.id as like_id, l.spotted_id as spotted_id,count(l.spotted_id) as numero_likes 
FROM sn_like_spotted l 
LEFT JOIN prof_foto f 
ON f.id = l.spotted_id 
LEFT JOIN sn_profilo p 
ON f.profilo_id = p.id 
WHERE p.id = 3 
GROUP BY l.spotted_id 
ORDER BY numero_likes DESC LIMIT 0,10 

이 쿼리를 입력 :

내가 IDENTITY

SELECT IDENTITY l.id as like_id, l.spotted as spotted_id,count(l.spotted) as numero_likes 

으로 시도하지만 난 (자세한 내가 QueryBuilder도 만들려고이 오류를

[Syntax Error] line 0, col 26: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '.' 

을 가지고 그런

[Semantical Error] line 0, col 36 near 'spotted as spotted_id,count(l.spotted)': Error: Invalid PathExpression. Must be a StateFieldPathExpression. 

:

나는이 오류가 기준, 동일한 결과)

,746,684,

내 오류는 내가 해결 CreateBuilder 경우에 대한 문제가

$q->orderBy($q->expr()->count('l.spotted'), 'desc'); 

답변

0

[Syntax Error] line 0, col 285: Error: Expected end of string, got '(' 

입니다 :

$q = $this->createQueryBuilder('l'); 
     $q->addSelect('count(l.spotted) as numero_likes'); 
     $q->leftJoin("l.spotted", 's'); 
     $q->leftJoin("s.profilo", 'p'); 
     $q->leftJoin("p.utente", 'u'); 
     $q->where('(s.foto_eliminata IS NULL OR s.foto_eliminata != 1)'); 
     $q->andWhere('p.fase_registrazione = :fase'); 
     $q->andWhere('u.locked = :false'); 
     $q->andWhere('p.id = :profilo_id'); 
     $q->setParameter(':fase', 100); 
     $q->setParameter('false', false); 
     $q->setParameter('profilo_id', $profilo_id); 
     $q->groupBy('l.spotted'); 
     $q->addOrderBy('numero_likes','DESC'); 
     $q->setMaxResults(10); 
     $dql = $q->getQuery(); 
     $results = $dql->execute(); 

     return $results; 

내가 내 결과에 numero_likes을하지 않으려면 내가 할 수있는 이것을하십시오 :

$q->addSelect('count(l.spotted) as HIDDEN numero_likes'); 

하지만 어떻게하면 createQuery에서이 작업을 수행 할 수 있습니다.