2011-09-23 7 views
2

이 작품은 :교리 2 쿼리 빌더 복근 기능

$qb = $this->em->createQueryBuilder(); 

    $qb->select("abs(u.code) as code") 
     ->from("User", "u") 
     ->orderBy("code","ASC") 
     ->getQuery() 
     ->getArrayResult(); 

이 작동하지 않음 :

$qb = $this->em->createQueryBuilder(); 

    $qb->select("u.code") 
     ->from("User", "u") 
     ->orderBy("abs(u.code)","ASC") 
     ->getQuery() 
     ->getArrayResult(); 

오류 :

구문 오류] 라인 0, COL 118 : 오류 : 예상되는 문자열 끝 '('

기본 doctrine 함수 abs 작업 전용 일부 문장의 경우 및 은 부품 주문에 따라 작동하지 않습니다.

것을 제외 :

1-) Im avoiding to use NativeQuery.

2-) u.code is a varchar fild on mysql and need to be varchar (some times numeric and some times string), and i need to order then like a number in numeric case.

어떤 도움?

+0

하지만 예외가 throw 된 -> getArrayResult(); 교리 API 내부 – JoeLoco

+0

표현식으로'ORDER BY'에 오류가 있다고 생각합니다. ("사용자", "u") -> orderBy ("abs_code", "ASC") -> getQuery에서 $ qb-> select ("abs 코드"로 "u.code, abs (u.code)() -> getArrayResult(); ' – atma

+0

이 작업은 이미이 작업을 시도하지만 내 시스템 구조가 다음과 같이 선택시 전체 개체를 기다리고 있습니다. $ qb-> select ("u"). .puf !! – JoeLoco

답변

2

해결 된 감사합니다 abs() realy는 orderBy에서 직접 작동하지는 않지만 별칭으로 작동합니다.

soluction

SELECT field1,field2,abs(field3) AS abs_field3 
FROM table 
ORDER BY abs_field3 ASC 

것을 제외 : 그것은 MySQL은 복근이 부분에 의해 순서에 직접 suports, 교리 제한이 아니라 MySQL의 제한입니다.