私は印刷した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();
私は、リポジトリfindメソッドについて読むが、これでは私が欲しいものではない、または私は完全にそれが機能しているか理解していています。
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