Doctrine을 사용하여 객체와 몇 개의 왼쪽 조인 만 반환하고 싶습니다.Doctrine DQL은 1 대 다수로 로딩을 중단합니다.
그러나 Doctrine (DQL 사용)은 모든 데이터를 계속로드합니다.
class User {
/**
* @ORM\OneToMany(targetEntity="NAMESPACE\Entity\TeamUserGroup", mappedBy="user")
*
* @var array
*/
protected $groups;
}
다음, TeamUserGroup 다시 대일의가 있습니다
public function fetchUser()
{
$qb = $this
->createQueryBuilder('s')
->select('s')
->andWhere('s.email=(:email)')
->addSelect('groups')->leftJoin('s.groups', 'groups')
->setParameter('email', $parameterBag['email']);
try {
return $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $exception) {
}
}
그리고 어떤 이유로 교리
그냥 EVERY 연결을로드 : 이것은 내 DQLclass TeamUserGroup {
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity="NAMESPACE\AuthBundle\Entity\User", inversedBy="groups")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*
* @var User
*/
private $user;
/**
* @ORM\Id()
* @ORM\ManyToOne(targetEntity="NAMESPACE\TeamBundle\Entity\Team", inversedBy="groups")
* @ORM\JoinColumn(name="team_id", referencedColumnName="id", nullable=false)
*
* @var Team
*/
private $team;
}
입니다.
그래서 나는이 구조를 가지고 :
// User Object
// All my Groups
// All the Teams of that Group
// All the Users in that team ...
나는이를 중지 할 수 있습니다 방법을 (그래서 난 그냥 내 객체를 얻고 왼쪽 조인).
// User Object
// All my Groups
고급에 감사 : 이 내 원하는 결과입니다.
을 도울 수 있기를 바랍니다 문제
More info here
를 해결하기 위해
doctrine partial objects
을 사용할 수 있습니다. Symfony Profiler에서 실행 된 SQL 쿼리는 무엇입니까? 열정적 인 로딩 문제는 일반적으로 양방향'OneToOne' 연관과 역변환에 대한 질의가있을 때만 발생합니다. [[sic] (https://github.com/doctrine/doctrine2/issues/4389)] 또는 스크립트가 Lazy Loaded 필드를 다른 곳에서 호출하고 있으며, Lazy Loaded 일 때 다른 데이터베이스 쿼리를 표시합니다. 나중에 나는 당신의 모범을 재창조 한 경우입니다. – fyrye제공된 코드가 설명 된 문제를 재현 할 수 없기 때문에이 질문을 닫는 투표. 원인을 정확하게 식별 할 수 있도록 실제 코드의 추가 컨텍스트로 질문을 업데이트하십시오. – fyrye