에 참여 곳 심포니 교리 QueryBuilder 내가 다음 선택하여 쿼리 빌더가 추가절에
$starterRepository = $this->getDoctrine()
->getManager()
->getRepository('CatalogBundle:Starter');
$query = $starterRepository->createQueryBuilder('s')
->where('s.active = 1')
->orderBy('s.voltage, s.power, s.serial');
그것은 테이블 "우선"을 선택,하지만 Starter.php 내부에서이 같은 연관성 "참조"가 :
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="StarterReference", inversedBy="starters")
* @ORM\JoinTable(name="starters_references")
*/
protected $references;
그래서 내 쿼리 결과에는 "starters"와 "starters_references"테이블이 있습니다. 1 시동기에는 많은 시동기 참고가있다. 이제 문제는 필자가 모든 시작 참조를 선택하는 것이 아니라 "ref_usage"라는 열에 값이있는 것을 선택해야한다는 것입니다.
->where('reference.ref_usage = 1')
을하지만이 방법은 내가 포함 한 모든 참조와 하나의 "시동"항목을 얻을 :
그래서 난 내 쿼리에 WHERE 절을 작성해야합니다, 나는 이것을 시도하고있다. 그리고 모든 초보자 항목은 필요하지만 ref_usage가있는 참조 만 필요합니다.
아이디어가 있습니까?
다음은 내가 사용중인 전체 파일 및 기능입니다.
컨트롤러 기능 : http://pastebin.com/0tTEcQbn
법인 "Starter.php" http://pastebin.com/BFLpKtec
법인 "StarterReference.php는" http://pastebin.com/Kr9pEMEW
편집 : 이 쿼리 I입니다 내가 사용하면 얻을 수있다 :
SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id0 FROM (SELECT s0_.id AS id0, s0_.serial AS serial1, s0_.voltage AS voltage2, s0_.power AS power3, s0_.rotation AS rotation4, s0_.teeth AS teeth5, s0_.module AS module6, s0_.b_terminal AS b_terminal7, s0_.comment AS comment8, s0_.commenten AS commenten9, s0_.commentru AS commentru10, s0_.commentpl AS commentpl11, s0_.commentde AS commentde12, s0_.commentes AS commentes13, s0_.type AS type14, s0_.adaptation AS adaptation15, s0_.alternative_product_1 AS alternative_product_116, s0_.alternative_product_2 AS alternative_product_217, s0_.alternative_product_3 AS alternative_product_318, s0_.alternative_product_4 AS alternative_product_419, s0_.active AS active20 FROM starters s0_ INNER JOIN starters_references s2_ ON s0_.id = s2_.starter_id INNER JOIN starter_reference s1_ ON s1_.id = s2_.starterreference_id WHERE s0_.active = 1 AND s1_.ref_usage = 1 ORDER BY s0_.voltage ASC, s0_.power ASC, s0_.serial ASC) dctrn_result) dctrn_table
당신이 그것을 볼 수 있듯이
->where('reference.ref_usage = 1')
1,363,210은 ref_usage = 1 절을 추가합니다. 하지만 문제는 여기서 필요 없다는 것입니다. 내부 참조를 참조 할 때 ref_usage 만 확인하면됩니다.
전체 쿼리 작성자 – Hooli
사용중인 전체 파일을 추가했습니다. 소식이 수정되었습니다. – The50