나는 인쇄 한 3D 객체를 저장하는 엔티티가 있습니다.Symfony doctrine 저장소가 엔티티의 인스턴스를 반환합니다.
private $id;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $images;
/**
* @ORM\Column(type="datetime")
*/
private $date_created;
/**
* @ORM\Column(type="datetime")
*/
private $date_modified;
/**
* @ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User")
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity="App\ThreedBundle\Entity\Threedobject", cascade={"all"})
*/
private $threedobject;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
가이처럼 보이는 SQL 쿼리 다음을 나타냅니다
select threedobject_id from threed_print where user_id = {RANDOM_NUMBER} group by threedobject_id;
나는 (내가 앱 \ ThreedBundle \ 엔티티 \ Threedobject 인스턴스를 의미)의 모든 인스턴스를 threedobject $를 얻을 수 있습니다 Doctrine을 통한 SQL 쿼리를 따르십시오. 다음 querybuilder를 시도했지만 값의 배열 표현을 반환했지만 대부분의 경우 요소의 메서드를 사용해야하므로 인스턴스를 가져 오려고합니다.
$query = $this->em->createQueryBuilder();
$result = $query
->select('tp')
->addSelect('to')
->from('ThreedBundle:ThreedPrint', 'tp')
->join('tp.threedobject', 'to')
->join('tp.user', 'u')
->where('u.id = :userID')
->groupby('to.id')
->setParameter('userID', $userID)
->getQuery();
return $result->getResult();
나는 저장소 찾기 방법에 대해 읽을 수 있지만이 내가 원하는 아니거나 작동 방법 나는 완전히 이해하고 있지 않다.
UPDATE :
내가 필요 기본적으로 무엇을 :
$query = $this->em->createQueryBuilder();
$result = $query
->select('to')
->from('ThreedBundle:ThreedPrint', 'tp')
->join('tp.threedobject', 'to')
->join('tp.user', 'u')
->where('u.id = :userID')
->groupby('to.id')
->setParameter('userID', $userID)
->getQuery();
return $result->getResult();
하지만 그것에 대해 다음과 같은 오류가 발생했습니다 :
'SELECT to FROM': Error: Cannot select entity through identification variables without choosing at least one root entity alias.
을 쓸 수 있지만, 문제는이 ID를 얻을 수 있지만 개체에 대한 엔터티의 인스턴스가 필요합니다. 고마워요 – PumpkinSeed
지금 본 링크가 있는데, 당신이 가진 것과 똑같은 문제에 대해 이야기 해 봤어? : http://stackoverflow.com/questions/17878237/doctrine-cannot-select-entity-through-identification- 변수를 선택하지 않고 –
나는이 오류 메시지에 대한 모든 게시물을 읽었으며 해결책을 얻지 못했습니다. – PumpkinSeed