I have an entity which store the 3D objects what I printed.
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;
There is a SQL query which looks like this:
select threedobject_id from threed_print where user_id = {RANDOM_NUMBER} group by threedobject_id;
I have to get the $threedobject all instance which (I mean the App\ThreedBundle\Entity\Threedobject instances) which represent the following sql query through Doctrine. I tried the following querybuilder, but it have returned the array representation of the values, but most of the cases I have to use the methods of the elements, so I want to get the instances.
$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();
I read about the repository find method, but in this is not what I want, or I'm not totally understand how it is working.
UPDATE:
Basically what I need:
$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();
But I got the following error for that:
'SELECT to FROM': Error: Cannot select entity through identification variables without choosing at least one root entity alias.